Mikro-orm: MongoDB: useUnifiedTopology

Created on 8 Sep 2019  路  4Comments  路  Source: mikro-orm/mikro-orm

I'm getting the following error message when MongoDB connection is initialized:

(node:18769) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.

As the error says, it's just a matter of adding useUnifiedTopology: true to this line: https://github.com/mikro-orm/mikro-orm/blob/master/lib/connections/MongoConnection.ts#L35
Not sure if it could cause any side-effect though.

| Dependency | Version |
| - | - |
| node | 8.13.0 |
| mikro-orm | 2.7.7 |
| mongodb | 3.3.2 |

dependencies

Most helpful comment

since 3.0.0-alpha.29 you can use driverOptions to append anything to driver configuration:

return MikroORM.init<MongoDriver>({
  entities: [...],
  dbName: '...',
  type: 'mongo',
  driverOptions: { useUnifiedTopology: true },
});

also tagging @seiyria as he was asking for this in the PR.

All 4 comments

Thanks for the report. Tried to upgrade mongodb to 3.3 and use the new flag, but there is a bug actually that breaks one test - isConnected() method will always return true now with the new topology enabled.

https://jira.mongodb.org/browse/NODE-2147

I'll enable this once that one is fixed.

Also this might be seen as a breaking change (passing the flag will require dependency update that won't be automatic as it's a peer dependency). So I'll rather leave this for v3, which will come in few weeks.

since 3.0.0-alpha.29 you can use driverOptions to append anything to driver configuration:

return MikroORM.init<MongoDriver>({
  entities: [...],
  dbName: '...',
  type: 'mongo',
  driverOptions: { useUnifiedTopology: true },
});

also tagging @seiyria as he was asking for this in the PR.

So the issue is finally fixed in v3.3.4.

Was this page helpful?
0 / 5 - 0 ratings