New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
DeprecationWarning: open()
is deprecated in mongoose >= 4.11.0, use openUri()
instead
#5399
Comments
+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));
}; |
So then, this is a bug? |
looks like a bug, can we workaround by adding |
Adding |
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
but it doesn't work |
Having same issue, even without replica sets. |
Having same issue:
|
Same... |
After I added below code to my mongo connection, I can't query out anything now. |
+1 same with replica sets, no sharding |
+1 |
1 similar comment
+1 |
+1 |
4 similar comments
+1 |
+1 |
+1 |
+1 |
The easiest fix for this; " |
+1 |
1 similar comment
+1 |
I get 2 messages:
The first error appeared in 4.11.0. The second error also appeared in the previous version of Mongoose. |
plhosk, the second one should have been fixed in 4.11 but looks like it's still there, for me too. |
+1 |
+1 sadly. |
Installed 4.10.8 without issues. Please consider changing |
+1 |
1 similar comment
+1 |
@iamdubx Sounds like you don't understand the difference between a warning and an error. The warning in question does not break anything, but warns the user of something that will be removed in the next major release.
So keep in mind, you're having this reaction to the developers warning you ahead of time before they remove a feature. I'd also urge you to remember that you're using this free of charge, so maybe give the developers the benefit of the doubt before you throw a tantrum |
It does pollute tests and console which is mildly annoying.
He is being impolite which is also mildly annoying but he makes a very valid point in regards to Mongoose documentation. It is not the worst documentation ever but it could really be improved. The fact that mongoose forwards the mongo client API. which works in a very different way, makes Mongoose usage and documentation confusing. A possible solution for this would be:
I would also suggest improving docs searchability by breaking it in several pages and giving more insight to new users about on what is Mongoose actually doing to achieve some of the results. |
I had this error, but it disappeared after I added {useMongoClient: true} option. (< any >mongoose).Promise = global.Promise; |
Just uninstall the current mongoose version which you have and install the lower version |
This solved my problem. But I had another warning coming up after I made this change.
|
This code solves all deprecation warnings: mongoose.Promise = global.Promise;
mongoose.connect(uri, {
keepAlive: true,
reconnectTries: Number.MAX_VALUE,
useMongoClient: true
}); More info by the link -> http://mongoosejs.com/docs/connections.html#use-mongo-client |
@bricss Fantastic! Thanks! |
@bricss You made my day. |
someone earned a hero badge... edit: @bricss It eliminated the deprecation warnings for me, but I couldn't retrieve data from my mLab sandboxes. It may be because they are using an older version of MongoDB. I'll try to check into it later. edit: @bricss It's now working correctly with the latest mongoose 4.11.9 and a connection to Cosmos DB on Azure. |
@bricss : Nicely done Bricks! It worked for me even though I'm using a really old version of mongodb in my local 👍 |
@bricss Awesowe! But you might consider putting a smaller number for "reconnectTries". You don't want to spend the whole day reconnecting if there is an issue with your DB. |
@Afoke 's solution worked for me, only when i explicitly declare the db in the connection string i.e. |
May I create connection to 2 DB's without this warning? I need to use my models with different DB's. |
Node was throwing a deprecation error related to mongoose. This is a known bug (Automattic/mongoose#5399) so I used a work-around to avoid it.
Using mongoose v^4.11.6 , when added
|
connecting to database in this way solves the problem: |
Will these errors cause problems , for example in security? |
No more "deprecated" warning pops up if I use this syntax 🎉
|
I faced the same deprecation warning as below: Solution I tried the following and it works fine. Gives no deprecation warnings. mongoose.connect('mongodb://127.0.0.1:27017/your-database-name', { useMongoClient: true, promiseLibrary: global.Promise }); Hope this will help everyone facing this issue. |
I have the same issue but when trying to connect to Mongo Atlas service it just not connect with {useMongoClient:true} option and without it the connection is no longer executed. Anyone with the same issue? |
I had solved my problem by just change the mongoose.connect to mongoose.createConnection mongoose.createConnection(config.uri, (err) => { |
I solved this problem like that (Mongoose 4.12.0, NodeJS - 7.10.1) mongoose.Promise = require('bluebird');
mongoose.connect('mongodb://localhost:27017/books_exchange', {
useMongoClient: true,
promiseLibrary: require('bluebird')
}).then(() => {
var userSchema = new mongoose.Schema({
name: String,
password: String
});
var User = mongoose.model('User', userSchema);
var person = new User({
name: "John",
password: "qwerty"
});
person.save().then(() => {
console.log('Data saved');
}).catch(e => {
console.log(e);
});
}).catch(e => {
console.log('Error while DB connecting');
console.log(e);
}); |
DeprecationWarning:
open()
is deprecated in mongoose >= 4.11.0, useopenUri()
instead, or set theuseMongoClient
option if usingconnect()
orcreateConnection()
Mongoose 4.11.0, MongoDB 2.2.29, NodeJS 8.1.2
The text was updated successfully, but these errors were encountered: