I am writing a mongodb connected app and while connecting to the server like bellow getting a warning like this:
Db.prototype.authenticate method will no longer be available in the next major release 3.x as MongoDB 3.6 will only allow auth against users in the admin db and will no longer allow multiple credentials on a socket. Please authenticate using MongoClient.connect with auth credentials.
My codes are like bellow
import mongoose from 'mongoose';
import config from './config';
mongoose.connect(config.db.uri);
at config.js
const config = {
name: 'API',
version: '0.0.1',
env: process.env.NODE_ENV || 'development',
port: process.env.PORT || 3000,
base_url: process.env.BASE_URL || 'http://localhost:3000',
db: {
uri: 'mongodb://admin:[email protected]:27017/ai?authSource=admin',
},
}
export default config;
I am using Node v8.0.0 and mongoose 4.10.5
Set the useCreateIndex global option to opt in to making Mongoose use createIndex() instead.
Is useNewUrlParser deprecated? The useNewUrlParser Option DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version.
The MongoDB server has deprecated the count() function in favor of two separate functions, countDocuments() and estimatedDocumentCount() . DeprecationWarning: collection. count is deprecated, and will be removed in a future version.
useUnifiedTopology: False by default. Set to true to opt in to using the MongoDB driver's new connection management engine. You should set this option to true , except for the unlikely case that it prevents you from maintaining a stable connection.
The warning is due to the MongoDB driver deprecating the API used by mongoose's default connection logic. As of mongoose 4.11.1 you can opt to use mongo client by setting the useMongoClient
option, for example
mongoose.connect(config.db.uri, { useMongoClient: true, /* other options */ })
Be reminded that using Mongo native client may have unwanted effects, so be sure to test everything out exhaustively
See more details here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With