From 1bae7943fad941abfacc30810e56e78064e82716 Mon Sep 17 00:00:00 2001 From: Ralph Date: Wed, 11 Sep 2019 15:37:42 +0200 Subject: [PATCH] Connect to mongo db 4.0.x using mongoose 5.7.0 Added support for connection setting useUnifiedTopology so it can be positioned via the database.json file in strapi project. By default it is positioned to false. If this is not set and you are connecting to a mongo db v4.0.x using the beta-16.1 and higher version of the strapi-hook-mongoose you will get the following warning message when starting the strapi server: 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. --- packages/strapi-hook-mongoose/lib/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/strapi-hook-mongoose/lib/index.js b/packages/strapi-hook-mongoose/lib/index.js index e90eecd394..f5c83a0097 100644 --- a/packages/strapi-hook-mongoose/lib/index.js +++ b/packages/strapi-hook-mongoose/lib/index.js @@ -56,6 +56,7 @@ module.exports = function(strapi) { password, database, srv, + useUnifiedTopology } = connection.settings; const uriOptions = uri ? url.parse(uri, true).query : {}; @@ -85,6 +86,7 @@ module.exports = function(strapi) { connectOptions.useNewUrlParser = true; connectOptions.dbName = database; connectOptions.useCreateIndex = true; + connectOptions.useUnifiedTopology = useUnifiedTopology || 'false'; try { /* FIXME: for now, mongoose doesn't support srv auth except the way including user/pass in URI.