DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0, use `openUri()` instead
DeprecationWarning: open() is deprecated in mongoose >= 4.11.0, use openUri() instead, or set the useMongoClient option if using connect() or createConnection()
Mongoose 4.11.0, MongoDB 2.2.29, NodeJS 8.1.2
+1 , I have no idea where to fix to get rid of that warning
The warning is for a code inside Mongoose actually, when connecting string has a replica set:
Mongoose.prototype.connect = function() {
var conn = this.connection;
if ((arguments.length === 2 || arguments.length === 3) &&
typeof arguments[0] === 'string' &&
typeof arguments[1] === 'object' &&
arguments[1].useMongoClient === true) {
return conn.openUri(arguments[0], arguments[1], arguments[2]);
}
if (rgxReplSet.test(arguments[0]) || checkReplicaSetInUri(arguments[0])) {
return new MongooseThenable(this, conn.openSet.apply(conn, arguments));
}
return new MongooseThenable(this, conn.open.apply(conn, arguments));
};
@tinovyatkin
So then, this is a bug?
looks like a bug, can we workaround by adding useMongoClient: true to options (you may see a deprecation from MongoDB driver then but that doesn't throw)
Adding useMongoClient: true makes the message disappear, but then my documents simply stop loading. Haven’t debugged it deeper, but I would prefer to hear best practices first before I adapt my code.
My application also doesn't work with the workaround suggested above. It simply doesn't run MyModel.find method anymore and gives no error and no timeout.
The reason why "useMongoclient: true" option doesn't work for most of the cases is for that option, every mongoose connection-related object returns dummy object cause not able to access mongodb
I tried to use it like
const server = express();
mongoose.connect('mongodb://localhost/advisorDemoTestDB', { useMongoClient: true })
.then(() => require('./db-init')(server))
.catch(err => console.error(err));
but it doesn't work
Having same issue, even without replica sets.
Having same issue:
(node:4138) DeprecationWarning: `open()` is deprecated in mongoose >= 4.11.0,
use `openUri()` instead, or set the `useMongoClient` option if using `connect()`
or `createConnection()`
Same...
After I added below code to my mongo connection, I can't query out anything now. {useMongoClient: true}. Any suggestions will be appreciate!!
+1 same with replica sets, no sharding
+1
+1
+1
+1
+1
+1
+1
The easiest fix for this; "npm remove mongoose" then "npm install [email protected] --save" problem solved. Upgrading is not always the best option.