Reputation: 21
Anyone knows the way around both of these two deprecation warnings:
(node:63440) DeprecationWarning: current URL string parser is deprecated, and wi
ll be removed in a future version. To use the new parser, pass option { useNewUr
lParser: true } to MongoClient.connect.
(node:63440) DeprecationWarning: current Server Discovery and Monitoring engine
is deprecated, and will be removed in a future version. To use the new Server Di
scover and Monitoring engine, pass option { useUnifiedTopology: true } to the Mo
ngoClient constructor.
the code that gave the error was like this at first:
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/fruitsDB');
but when I try to fix it by passing {userNewUrlParser: true} it works for the first deprecation but the second deprecation remains and if I pass all the two the code breaks completely I tried:
const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/fruitsDB', { useNewUrlParser: true });
and that fixed the first deprecation, I also tried
mongoose.connect('mongodb://localhost:27017/fruitsDB', { useUnifiedTopology: true });
and that fixed the second deprication but I don't know how to fix both the two in my case I tried
mongoose.connect('mongodb://localhost:27017/fruitsDB', { useNewUrlParser: true },{ useUnifiedTopology: true });
and that completely ruined my app I installed mongodb version v4.2.5 on the pc and the dependencies on the package.json are as follows:
"dependencies": {
"express": "^4.17.1",
"lodash": "^4.17.15",
"mongodb": "^3.5.7",
"mongoose": "^5.9.13",
"nodemon": "^2.0.3"
}
Upvotes: 1
Views: 209
Reputation: 1
mongoose.connect("mongodb://localhost:27017/fruitsDB",{
useNewUrlParser: true ,
useUnifiedTopology: true
});
TRY this out!!!!
Upvotes: 0
Reputation: 21
I got the fix around multiple deprecations at once on Mongoclient and that is to use the mongoose.set('whatever', true); as for the issue I raised before the fix is:
const mongoose = require('mongoose');
mongoose.set('useNewUrlParser', true);
mongoose.set('useUnifiedTopology', true);
mongoose.connect('mongodb://localhost:27017/fruitsDB');
The first line fill fix the first error and the second line will fix the second error
Upvotes: 1