-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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
Can't Connect To MongoDB Atlas Cluster #3347
Can't Connect To MongoDB Atlas Cluster #3347
Comments
Did you try add |
Try add |
Thanks guys -- yes, I added useNewUrlParser. Oddly, it still gives a warning even though it gets passed. Also, the dbName is unnecessary since the database name gets passed in as part of the URL connection string. I believe there is something awry with how the Mongo Driver works with typeOrm. At first blush, looking at the code in the Mongo Driver, I see how all these nullable options get set, which could be problematic. It would be nice to construct the options object with only the values passed. |
After few tries I have two valid configurations for typeorm and mongo atlas: const connection = await createConnection({
type: "mongodb",
useNewUrlParser: true,
url: "mongodb://admin:password@testcluster0-shard-00-00-1cmyo.mongodb.net:27017,testcluster0-shard-00-01-1cmyo.mongodb.net:27017,testcluster0-shard-00-02-1cmyo.mongodb.net:27017/test?ssl=true&replicaSet=TestCluster0-shard-0&authSource=admin&retryWrites=true",
ssl: true,
authSource: "admin",
replicaSet: "TestCluster0-shard-0"
}); and second one const connection = await createConnection({
type: "mongodb",
url: "mongodb+srv://admin:admin@testcluster0-1cmyo.mongodb.net/test?retryWrites=true",
ssl: true,
authSource: "admin",
replicaSet: "TestCluster0-shard-0"
}); But I think @pointtoken is right. Calling mongodb connect method with undefined option properties overwrites settings from url. |
@vlapo nice that worked! |
Still I think we should not pass all mongo options to mongo client with undefined values. Our current implementation will overwrite all options from url with |
I know it's a closed case... .env TYPEORM_CONNECTION = mongodb
TYPEORM_URL = mongodb+srv://admin:password@cluster-XXXXX-pSDig.mongodb.net/graphql-ts?retryWrites=true&w=majority
TYPEORM_DATABASE = graphql-ts
TYPEORM_ENTITIES = src/entity/*.ts
TYPEORM_MIGRATIONS = src/migration/**/*.ts
TYPEORM_ENTITIES_DIR = src/entity
TYPEORM_SUBSCRIBERS_DIR = src/subscriber
TYPEORM_MIGRATIONS_DIR = src/migration
TYPEORM_DRIVER_EXTRA = '{"useUnifiedTopology":true}' |
Hello, I have the same problem with a free Mongo Atlas cluster.
I'm using nestjs, but with mongoose all works fine. But i'd like using typeorm because i need multiple connections with other kind of databases. I don't think it's a problem of @nestjs/typeorm package. |
@oliviermattei facing the same issue did you find a solution to this. |
Updating this ticket with a code block that got mine to work, using the free cluster.
|
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
I had the same issue. Passing the MongoDB Atlas as URL (mongodb://) lead to the Since I didn't want to change my environment variable in my environment, I fixed this by creating a method that parses the URL and constructs the options correctly. Here are the details of the implementation in case it becomes handy for anybody else.
Here is what my ormconfig.json looks like:
I am using "mongodb": "^3.6.3", "typeorm": "^0.2.29". P.S. Please note that this implementation doesn't account for cases where the configuration has a parameter with a number value (but it is an easy fix to add if you are sending a parameter that has a numeric value in the URL). |
I am still getting this problem with typeorm 0.2.29. EDIT: I found a working but undocumentend solution, if you use one of your cluster shard addresses instead of the general address mongo atlas gives you, the connection works So instead of hope it helps |
@PierBusDev is correct. MongoDB Atlas support is currently broken unless you specify the exact shard you want to connect to. Wasted a few hours on this :/ This issue should be re-opened with a fix or with some documentation. |
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
Can confirm - using the shard worked when using nestjs, typeorm and mongodb atlas 🤦 |
v0.2.30 fixes the issue. Can connect to an atlas cluster again. Thanks @pleerock! |
Hmm. So, we seem to be in a catch-22. I upgraded to 0.2.30, but did not change my mongo connection string, which I REVERTED to a After upgrading to 0.2.30 a short while ago, our connection to mongo stopped working. It just would time out trying to connect. We updated numerous modules at once, and it took a bit of experimentation to figure out that it is the 0.2.30 version of TypeORM that is causing the problem. So while we may have gained the ability to use I would offer it is best if we can use both types of connection strings, as necessary, to connect TypeORM to various mongo databases. |
So the below worked for me. I am using Nestjs
|
Thank you @AmbassEugene, it worked for me. |
Thank you @AmbassEugene , it worked with your setup. |
This doesn't seem to work anymore? edit: Looks like |
Issue type:
[ ] question
[X] bug report
[ ] feature request
[ ] documentation issue
Database system/driver:
[ ]
cordova
[X]
mongodb
[ ]
mssql
[ ]
mysql
/mariadb
[ ]
oracle
[ ]
postgres
[ ]
sqlite
[ ]
sqljs
[ ]
react-native
[ ]
expo
TypeORM version:
[X]
latest
[ ]
@next
[ ]
0.x.x
(or put your version here)Steps to reproduce or a small repository showing the problem:
I have a valid connection string to a Mongo Atlas DB that I am trying to use with TypeORM. I know the connection string works because I have used it from Python and from the Mongo shell. But it doesn't work from typeorm. I have tried both the mongodb:// and mongo+srv synax. Not sure how to debug or figure this one out. Here is the error:
The text was updated successfully, but these errors were encountered: