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: useNewUrlParser: true #6667
Comments
see #6656, #6648, #6647, #6651 for more info @marianagarciaferreira. How you handle this essentially boils down to how complex your connection is, and whether or not you are willing to silence deprecation warnings while using mongoose 5.2.1. If you're connecting to a single server like localhost, just be sure to specify the port in your URI and add useNewUriParser: true to your connection options. If you're connecting to a hosted service like Atlas or any kind of replica set, etc then you can either continue to use the old url parser ( you can temporarily silence the deprecation warnings with |
@lineus I am passing const config = {
autoIndex: false,
useNewUrlParser: true,
};
return mongoose.connect(uri, {config}); Result:
It appears as if Mongoose is not passing it along to the Mongo client properly, any thoughts? |
@adamreisnz are you requiring/importing any modules (plugins etc) that also connect to the db? |
I don't, no.
…On Thu, Jul 26, 2018, 22:17 Kev ***@***.***> wrote:
@adamreisnz <https://github.com/adamreisnz> are you requiring/importing
any modules (plugins etc) that also connect to the db?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6667 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAd8QsNOMQCYeUHi8K3Oeu0Vn06aPaQCks5uKZcngaJpZM4VDDOD>
.
|
|
Doh, you are right, easy to miss that... >.< Now it looks like it's trying to use the new parser, but telling me "port must be specified", for connection string |
yeah, the newUrlParser doesn't allow the implicit default port, there's a native driver bug for it. For now you have to specify the port with the new url parser. |
I continue with the error my options .ENV My Vars mongo: { here connect exports.connect = () => { even though the error appears on the console. (node:1984) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect. |
I did specify the port, hence my question
…On Thu, Jul 26, 2018, 23:04 Kev ***@***.***> wrote:
yeah, the newUrlParser doesn't allow the implicit default port, there's
an native driver bug for it <https://jira.mongodb.org/browse/NODE-1547>.
For now you have to specify the port with the new url parser.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#6667 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAd8QiI2-FidPvrdBXW0x500SydSOmT7ks5uKaI5gaJpZM4VDDOD>
.
|
@marianagarciaferreira the first thing that stands out from your code sample is that your .env doesn't show a property that lines up with either side of this ternary ( but that doesn't explain your error ):
I'll play around with your code and see if I can suss out what's going wrong. @adamreisnz My bad, I didn't catch that. If you're not including any other packages that call This stand alone example works without error: test.js#!/usr/bin/env node
'use strict';
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/test', { useNewUrlParser: true });
const conn = mongoose.connection;
const Schema = mongoose.Schema;
const schema = new Schema({
name: String
});
const Test = mongoose.model('test', schema);
const test = new Test({ name: 'one' });
async function run() {
console.log(`Mongoose: ${mongoose.version}`);
await conn.dropDatabase();
await test.save();
let found = await Test.findOne();
console.log(found);
return conn.close();
}
run(); Output:
Can you craft an example that shows the error when passing in the port in the connection string? |
@marianagarciaferreira I tried to replicate what you're seeing in a complete example but it works for me. The one mistake I made while making this example was that I instinctively called index.js#!/usr/bin/env node
'use strict';
const db = require('./conn');
async function run() {
const conn = await db.connect();
const Test = conn.model('test', { name: String });
const test = new Test({ name: 'test' });
await conn.dropDatabase();
await test.save();
let found = await Test.findOne({});
console.log(found);
return conn.close();
}
run().catch(console.error); conn.js'use strict';
const mongoose = require('mongoose');
console.log(`Mongoose: ${mongoose.version}`);
const mongo = {
uri: 'mongodb://localhost:27017/test',
opt: {
useNewUrlParser: true
}
};
exports.connect = () => {
return mongoose.connect(mongo.uri, mongo.opt)
.then(() => { return mongoose.connection; });
}; Output:
|
@lineus I've isolated the issue, it was a config being overwritten on our end, so with the port it is in fact working correctly. I will follow the other issue to stay updated on when the default port works again, thanks! |
Passing
Removing the options stops the error, however it starts showing the |
@pSnehanshu what version of mongoose are you using? what does your connection configuration look like? please share an example of how you're connecting to mongoose with any sensitive information redacted. |
@lineus This is how I'm trying to connect:
|
@pSnehanshu what version of mongoose are you using? |
@lineus |
@pSnehanshu if possible can you update to @latest and try again. There were issues with the underlying driver in mongoose 5.2.0. The latest fixes for the driver are included in 5.2.9. |
@lineus No, upgrading to v5.2.9 didn't help, instead it is spitting out even more warnings: |
I have also posted the issue in MongoDB Jira. |
@pSnehanshu when I suggested that you upgrade I thought you were using 5.2.0, and I was unaware of the new deprecation warnings in 5.2.9. Now that I know you're using above 5.2.0 I'll try and replicate the issue with you. It might be easier if you joined either Gitter.im or Slack to chatabout it in real time. |
@lineus I am on gitter |
Hi @lineus I am having the same issue as @pSnehanshu after upgrading mongoose. I am seeing the |
@alanosman this is something that mongoose will have to deal with eventually, by a passing For now, you'll have to ignore this specific deprecation warning. This is a result of mongoose updating to the latest version of the mongodb native js driver. They have added deprecation warnings for several methods and the option you mentioned. You can see the details in the diff here There's also a bug opened in this queue for this issue that you can follow. |
Same issue here |
+1 |
Same issue with deprecated .find() method |
I am working with Mongoose const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/testdb', {useNewUrlParser: true})
.then(() => console.log('connecting to database successful'))
.catch(err => console.error('could not connect to mongo DB', err)) |
still does not work
|
@apyrkh this is a known issue. For now, when using the srv record, you need to provide your user/pass in the connection string to use the new URL parser. Alternatively, you can skip the new URL parser and live with the deprecation warnings. The latest version of the native driver fixes this issue. The updated driver will land in mongoose soon. |
warning in debug
DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
Does anyone know how to fix this alert?
The text was updated successfully, but these errors were encountered: