Skip to content
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: 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. #8156

Closed
its-me-ilia opened this issue Sep 11, 2019 · 20 comments

Comments

@its-me-ilia
Copy link

Hi, I just downloaded latest version of mongoose from npm and tried to run it but it gave me this warning:
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.

i added this option to my configuration but it still gives me this warning. here is my configuration

mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true, useFindAndModify: false, useCreateIndex: true, useUnifiedTopology: true }).then(()=>{ console.log(connection to database established) }).catch(err=>{ console.log(db error ${err.message}); process.exit(-1) })

any clue?

@felipeplets
Copy link
Contributor

felipeplets commented Sep 12, 2019

Same is happening to me.

There is also your thread about it on StackOverflow: https://stackoverflow.com/questions/57895175/server-discovery-and-monitoring-engine-is-deprecated/57899638#57899638

@TREagans
Copy link

TREagans commented Sep 18, 2019

This works fine for me, and no more errors.

mongoose
.connect(process.env.MONGO_URI, {
useUnifiedTopology: true,
useNewUrlParser: true,
})
.then(() => console.log('DB Connected!'))
.catch(err => {
console.log(DB Connection Error: ${err.message});
});

@portothree
Copy link

portothree commented Sep 20, 2019

This works fine for me, and no more errors.

mongoose
.connect(process.env.MONGO_URI, {
useUnifiedTopology: true,
useNewUrlParser: true,
})
.then(() => console.log('DB Connected!'))
.catch(err => {
console.log(DB Connection Error: ${err.message});
});

I was facing the same error and "useUnifiedTopology: true" fixed, thanks! It's already updated on the readme of the repo btw

@jiobiagba
Copy link

This works fine for me, and no more errors.

mongoose
.connect(process.env.MONGO_URI, {
useUnifiedTopology: true,
useNewUrlParser: true,
})
.then(() => console.log('DB Connected!'))
.catch(err => {
console.log(DB Connection Error: ${err.message});
});

Adding the useUnifiedTopology: true to the object after my connection URL worked just as you suggested though I was using MongoClient. Thanks!

@kimprosh
Copy link

kimprosh commented Sep 25, 2019

It still error:

const options = {
    keepAlive: 1,
    useUnifiedTopology: true,
    useNewUrlParser: true,
  };
  mongoose.connect(dbUrl, options).then(() => console.log('DB connected'));

It output:

(node:14923) 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.

Anyone can help me? Thanks!

@sinhagyandeep
Copy link

This works fine for me, and no more errors.
mongoose
.connect(process.env.MONGO_URI, {
useUnifiedTopology: true,
useNewUrlParser: true,
})
.then(() => console.log('DB Connected!'))
.catch(err => {
console.log(DB Connection Error: ${err.message});
});

I was facing the same error and "useUnifiedTopology: true" fixed, thanks! It's already updated on the readme of the repo btw

@jiobiagba Yes i have tried your solution now my node.js server is not showing me any error simply it is showing 'The Server Is Running On Port:7070'.

Thanks for the solution hope no error will come.

@douglasmartins7
Copy link

I was having the same problem and when inserting useUnifiedTopology: true, stopped showing terminal error.

Folow code:

mongo() {
this.mongoConnection = mongoose.connect(process.env.MONGO_URL, {
useUnifiedTopology: true,
useNewUrlParser: true,
useFindAndModify: true,
});
}

@cbratschi
Copy link

This parameter does not work with our replica set URL:

error:getaddrinfo ENOTFOUND .xyz.net .xyz.net:12345

Are there any replica set changes needed on top of this parameter?

@sinhagyandeep
Copy link

@cbratschi can you please explain in details cause i want exact error and code so further i can try to help you.

@guhandelta
Copy link

guhandelta commented Oct 2, 2019

I too faced the same issue and after inserting useUnifiedTopology: true, I don't face any errors, but the console log in the .then() block does not get executed.

mongoose.connect(MONGODB_URI,{ useNewUrlParser: true, useUnifiedTopology: true })
.then(()=> console.log('Database Connection Successful!!'))
.catch(err => console.error(err));

@sinhagyandeep
Copy link

@guhandelta none of code is executing (.then() and .catch()) ?

@guhandelta
Copy link

Yes... none, I don't get any console logs on my cmd prompt or errors.

server/index.js =>
node indexjs

npm run dev =>
npm run dev

@cbratschi
Copy link

cbratschi commented Oct 2, 2019

@cbratschi can you please explain in details cause i want exact error and code so further i can try to help you.

I only see these lines in the log message and the stacktrace contains the same information:

    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:57:26)
(node:7740) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

This is the URL we are using (anonymized):

mongodb://user:pwd@abc.xyz.net:27018,.xyz.net:27019,.xyz.net:27020/account?replicaSet=mongors&readPreference=primaryPreferred

Update: it works if the abc sub-domain part is repeated in the URI. For instance:

mongodb://user:pwd@abc.xyz.net:27018,abc.xyz.net:27019,abc.xyz.net:27020/account?replicaSet=mongors&readPreference=primaryPreferred

@sinhagyandeep
Copy link

@cbratschi can you please review your code once cause it will direct give the idea here the error is saying the same.it might possible that you are leaving some code for handling catch or async code or you might have missed promise which is compulsory in non-blocking.

@pabloabreu1986
Copy link

Hello, I have:

mongoose
.connect(process.env.MONGO_URI, {
useUnifiedTopology: true,
useNewUrlParser: true,
})
.then(() => console.log('DB Connected!'))
.catch(err => {
console.log(Error, err.message);
});

When it starts I get at the console:
[Function: Error] { stackTraceLimit: 16, prepareStackTrace: undefined } connection 0 to acccluster-shard-00-01-xx47j.mongodb.net:27017 closed

@cbratschi
Copy link

@cbratschi can you please review your code once cause it will direct give the idea here the error is saying the same.it might possible that you are leaving some code for handling catch or async code or you might have missed promise which is compulsory in non-blocking.

The subdomain was not parsed correctly in the implementation. Switching to full domains it works fine now (see my last comment). So the implementation is not fully standard compliant.

@franciscosuca
Copy link

This works fine for me, and no more errors.

mongoose
.connect(process.env.MONGO_URI, {
useUnifiedTopology: true,
useNewUrlParser: true,
})
.then(() => console.log('DB Connected!'))
.catch(err => {
console.log(DB Connection Error: ${err.message});
});

I was using the method indicated in this link, but it didn't work. After using the useUnifiedTopology option in the mongoose.connect() it worked!

@jbmulligan
Copy link

I found my way here because I am having the same problem - I just switched to the latest version of mongodb, and I get the warning. I added useUnifiedTopology to the options passed to the MongoClient constructor, but the warning persists. The connection to the remote database seems fine, the operations are succeeding and there are no other error messages or warnings. My url is: mongodb://myUsername:myPassword@myHostName.org:27017/myDatabaseName

@Ginholuca
Copy link

I fixed this bug with this:

mongoose.connect('mongodb+srv: {...}', {
useNewUrlParser: true,
useUnifiedTopology: true
});

@vkarpov15
Copy link
Collaborator

Please follow the instructions on the docs here: https://mongoosejs.com/docs/deprecations.html

@Automattic Automattic locked as resolved and limited conversation to collaborators Oct 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests