Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue connecting with MongoDB Atlas Cluster #3133

Closed
charlieroth opened this issue Nov 20, 2018 · 5 comments · Fixed by #7136
Closed

Issue connecting with MongoDB Atlas Cluster #3133

charlieroth opened this issue Nov 20, 2018 · 5 comments · Fixed by #7136

Comments

@charlieroth
Copy link

charlieroth commented Nov 20, 2018

Issue type:

[x] question
[ ] bug report
[ ] feature request
[ ] documentation issue

Database system/driver:

[ ] cordova
[x] mongodb
[ ] mssql
[ ] mysql / mariadb
[ ] oracle
[ ] postgres
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo

TypeORM version:

[ ] latest
[ ] @next
[x] 0.2.9 (or put your version here)

package.json:

{
   "name": "...",
   "version": "...",
   "description": "...",
   "devDependencies": {
      "ts-node": "7.0.1",
      "@types/node": "^10.12.9",
      "typescript": "3.1.6"
   },
   "dependencies": {
      "@types/dotenv": "^6.1.0",
      "dotenv": "^6.1.0",
      "mongodb": "^3.1.10",
      "reflect-metadata": "^0.1.10",
      "tslint": "^5.11.0",
      "typeorm": "0.2.9"
   },
   "scripts": {
      "start": "..."
   }
}

Steps to reproduce or a small repository showing the problem:

import * as dotenv from "dotenv";
import "reflect-metadata";
import { createConnection } from "typeorm";

dotenv.config();
createConnection({
    cli: {
        entitiesDir: "src/entity",
        migrationsDir: "src/migration",
        subscribersDir: "src/subscriber",
    },
    entities: [
        "src/entity/**/*.ts",
    ],
    logging: true,
    migrations: [
        "src/migration/**/*.ts",
    ],
    subscribers: [
        "src/subscriber/**/*.ts",
    ],
    synchronize: true,
    type: "mongodb",
    url: `mongodb+srv://${process.env.MONGODB_ATLAS_USERNAME}:${process.env.MONGODB_ATLAS_PASSWORD}@inquisitive-cluster-1-j18op.mongodb.net/inquisitive-db?retryWrites=true`,
}).then(async (connection) => {
    console.log("Connection succesful");
    console.log("Connection: ", connection);
}).catch((error) => {
    console.log("Connection failed");
    console.log(error);
});

When I run npm start I get the following error:

(node:3634) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.

I see older issues with a similar problem and was wondering if an update in the MongoDB node driver is causing this or if this is due to my configuration settings?

@nik-amir
Copy link

I've never used MongoDB Atlas Cluster before, but I think you need to include useNewUrlParser: true in your createConnection options.

import * as dotenv from "dotenv";
import "reflect-metadata";
import { createConnection } from "typeorm";

dotenv.config();
createConnection({
    cli: {
        entitiesDir: "src/entity",
        migrationsDir: "src/migration",
        subscribersDir: "src/subscriber",
    },
    entities: [
        "src/entity/**/*.ts",
    ],
    logging: true,
    migrations: [
        "src/migration/**/*.ts",
    ],
    subscribers: [
        "src/subscriber/**/*.ts",
    ],
    synchronize: true,
    useNewUrlParser: true
    type: "mongodb",
    url: `mongodb+srv://${process.env.MONGODB_ATLAS_USERNAME}:${process.env.MONGODB_ATLAS_PASSWORD}@inquisitive-cluster-1-j18op.mongodb.net/inquisitive-db?retryWrites=true`,
}).then(async (connection) => {
    console.log("Connection succesful");
    console.log("Connection: ", connection);
}).catch((error) => {
    console.log("Connection failed");
    console.log(error);
});

@vlapo
Copy link
Contributor

vlapo commented Dec 6, 2018

Similar issue #2650

@pointtoken
Copy link

I'm seeing this as well. But the issue for me isn't just getting a warning; I can't connect via typeorm to a mongodb atlas cluster at all. What are the tricks for getting typeorm to connect to a mongodb atlas cluster? (Works fine against a local mongodb instance)

@vlapo
Copy link
Contributor

vlapo commented Jan 4, 2019

@charlieroth if this issue is only about warning please, please see this comment #2650 (comment).

If there is problem with connect to mongo atlas please check this answer #3347 (comment)

Let me know if this help.

@vlapo
Copy link
Contributor

vlapo commented Jan 7, 2019

This issue should be fixed by #3366 and will be in next release. Feel free reopen if problem persists.

@vlapo vlapo closed this as completed Jan 7, 2019
nocheintobi added a commit to nocheintobi/typeorm that referenced this issue Dec 2, 2020
As described in [MongoDB Docs](https://docs.mongodb.com/manual/reference/connection-string/#dns-seed-list-connection-format), an additional connection string format called DNS Seed List Connection format can be used. As this is the default format for MongoDB Atlas, the hosted service of MongoDB, this should be available also for typeorm. 
The connection format is identified by the url-schema "mongodb+srv" and does not allow specifying a port.
Fixes typeorm#3347
Fixes typeorm#3133
pleerock pushed a commit that referenced this issue Dec 22, 2020
As described in [MongoDB Docs](https://docs.mongodb.com/manual/reference/connection-string/#dns-seed-list-connection-format), an additional connection string format called DNS Seed List Connection format can be used. As this is the default format for MongoDB Atlas, the hosted service of MongoDB, this should be available also for typeorm. 
The connection format is identified by the url-schema "mongodb+srv" and does not allow specifying a port.
Fixes #3347
Fixes #3133
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants