typeorm: Can't Connect To MongoDB Atlas Cluster
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:
(node:19257) 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.
{ MongoNetworkError: connection 5 to cluster0-XXXX.mongodb.net:27017 closed
at Socket.<anonymous> (/home/administrator/Source/Repos/emoon-relayer/node_modules/mongodb-core/lib/connection/connection.js:276:9)
at Object.onceWrapper (events.js:273:13)
at Socket.emit (events.js:182:13)
at TCP._handle.close (net.js:611:12)
name: 'MongoNetworkError',
errorLabels: [ 'TransientTransactionError' ],
[Symbol(mongoErrorContextSymbol)]: {} }
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 1
- Comments: 20 (6 by maintainers)
Commits related to this issue
- fix,feat: support MongoDB DNS seed list connection As described in [MongoDB Docs](https://docs.mongodb.com/manual/reference/connection-string/#dns-seed-list-connection-format), an additional connecti... — committed to nocheintobi/typeorm by nocheintobi 4 years ago
- fix: support MongoDB DNS seed list connection (#7136) As described in [MongoDB Docs](https://docs.mongodb.com/manual/reference/connection-string/#dns-seed-list-connection-format), an additional conne... — committed to typeorm/typeorm by nocheintobi 4 years ago
After few tries I have two valid configurations for typeorm and mongo atlas:
and second one
But I think @pointtoken is right. Calling mongodb connect method with undefined option properties overwrites settings from url.
So the below worked for me. I am using Nestjs
I am still getting this problem with typeorm 0.2.29. None of the solutions posted above work right now
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
mongodb+srv://<user>:<password>@cluster0.somethingsomething.mongodb.net/<dbname>use something like (you’ll find three valid for your conf in your mongoatlas page):mongodb+srv://<user>:<password>@cluster0-shard-00-00.somethingsomething.mongodb.net/<dbname>hope it helps
I know it’s a closed case… but since I’m using dotenv and MongoDB Atlas this is what I found :
.env
@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.
Updating this ticket with a code block that got mine to work, using the free cluster.
Hello,
I have the same problem with a free Mongo Atlas cluster.
[TypeOrmModule] Unable to connect to the database. Retrying (1)... +2006msI’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.