typeorm: MongoDB MongoServerSelectionError: getaddrinfo ENOTFOUND
Issue Description
When I try to make a normal mongodb connection with typerom@0.2.29 version I get this error:
MongoDB MongoServerSelectionError: getaddrinfo ENOTFOUND [Mongodb Server IP]
but when I try to make a normal mongodb connection with typerom@0.2.25 version it works.
Expected Behavior
Must connect to mongodb server
Actual Behavior
throws this error:
MongoDB MongoServerSelectionError: getaddrinfo ENOTFOUND [Mongodb Server IP]
Steps to Reproduce
- install typeorm@0.2.29
- connect to a mongodb server with default options
typeorm.createConnection({
type: "mongodb",
url: CONFIG.MONGODB_URI,
synchronize: true,
logger: "debug",
useUnifiedTopology: true,
useNewUrlParser: true,
autoLoadEntities: true,
})
My Environment
| Dependency | Version |
|---|---|
| Operating System | Windows10 |
| Node.js version | v15.0.1 |
| Typescript version | v3.7.4 |
| TypeORM version | v0.2.29 |
Additional Context
Relevant Database Driver(s)
-
mysql -
aurora-data-api -
aurora-data-api-pg -
better-sqlite3 -
cockroachdb -
cordova -
expo -
mongodb -
nativescript -
oracle -
postgres -
react-native -
sap -
sqlite -
sqlite-abstract -
sqljs -
sqlserver
Are you willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time, and I know how to start.
- Yes, I have the time, but I don’t know how to start. I would need guidance.
- No, I don’t have the time, although I believe I could do it if I had the time…
- No, I don’t have the time and I wouldn’t even know how to start.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 14
- Comments: 22 (3 by maintainers)
Commits related to this issue
- Downgrade typeorm to v0.2.28, issue: https://github.com/typeorm/typeorm/issues/7009 — committed to ArtCodeStudio/parcel-lab-shopify-app by JumpLink 4 years ago
Fix was merged and will be in
v0.2.30later this week.Same here, works with
v0.2.28but not withv0.2.29, connect url ismongodb+srv://<hidden>:<hidden>@cluster0.fbbdh.mongodb.net/<hidden>?retryWrites=true&w=majority"@pleerock, I am waiting for the update. I’m trying to use Next-Auth.js. When the update will be released?
Any news about it? Tried to use typeorm with mongodb atlas and it doesn’t work in any way
Same here.
I’m also using MongoDB Atlas. For weeks i’ve been using the same configuration, but today i had to recreate my node_modules, and it stopped working.
[Nest] 33020 - 05/11/2020 03:03:18 [TypeOrmModule] Unable to connect to the database. Retrying (6)... +3005ms MongoNetworkError: failed to connect to server [cluster0-unwqs.mongodb.net:27017] on first connect [Error: getaddrinfo ENOTFOUND cluster0-unwqs.mongodb.net at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:66:26) { name: 'MongoNetworkError', [Symbol(mongoErrorContextSymbol)]: {} }] at Pool.<anonymous> (C:\projetos\rolla-dev\node_modules\mongodb\lib\core\topologies\server.js:438:11) at Pool.emit (events.js:314:20) at Pool.EventEmitter.emit (domain.js:486:12) at C:\projetos\rolla-dev\node_modules\mongodb\lib\core\connection\pool.js:561:14 at C:\projetos\rolla-dev\node_modules\mongodb\lib\core\connection\pool.js:994:11 at C:\projetos\rolla-dev\node_modules\mongodb\lib\core\connection\connect.js:31:7 at callback (C:\projetos\rolla-dev\node_modules\mongodb\lib\core\connection\connect.js:264:5) at Socket.<anonymous> (C:\projetos\rolla-dev\node_modules\mongodb\lib\core\connection\connect.js:294:7) at Object.onceWrapper (events.js:421:26) at Socket.emit (events.js:314:20)EDIT:
This is my version:
"typeorm": "^0.2.29",I was using 0.2.24 but it does not work either.
👋 I encountered this issue today while using next-auth (which uses typeorm). Here are my versions:
I was able to replicate directly with typeorm as @barbarbar338 suggested, using the following script and a free mongodb atlas instance.
Errors:
However, I’m unable to successfully run the script above with typeorm@0.2.28. I’m able to successfully connect to the same Mongo Atlas instance without typeorm and the following example script:
Additionally, I am able to connect to a local version of mongodb, so there’s a chance this could be an issue with Mongo Atlas and not typeorm.
@FcoMarcosMAbreu in the meantime, if you still have the issue, you can drop a
npm i typeorm@0.2.28in your project, it will override the typeorm’s version next-auth has installed. Just did it yesterday as I had the issue and now it works fine ! Good luck!This worked for me
I’ve got the same error on 0.2.29
I tried to trace the error by cloning TypeORM to my local FS, compiling and linking it in my repository… But then it works as normal. Was expecting the error to originate from #6925
Steps I took (more-or-less):
EDIT: 0.2.28 works fine