I am trying to access the Mongo DB with the new mongoose version (4.11.0): "mongoose.connect("mongodb://localhost/restful_blog_app");"
I got the following message:open()
is deprecated in mongoose >= 4.11.0, use openUri()
instead, or
set the useMongoClient
option if using connect()
or createConnection()
I tried the following fix:
"mongoose.connect("mongodb://localhost/restful_blog_app", {useMongoClient: true});"
Conclusion: That message has disappeared, but the DB I just created has no data!
Please help!
Connecting to MongoDBMongoose requires a connection to a MongoDB database. You can require() and connect to a locally hosted database with mongoose. connect() as shown below (for the tutorial we'll instead connect to an internet-hosted database). You can get the default Connection object with mongoose.
You can connect to MongoDB with the mongoose.connect() method. mongoose.connect('mongodb://localhost:27017/myapp'); This is the minimum needed to connect the myapp database running locally on the default port (27017). If connecting fails on your machine, try using 127.0.0.1 instead of localhost .
Mongoose is built untop of mongodb driver, the mongodb driver is more low level. Mongoose provides that easy abstraction to easily define a schema and query. But on the perfomance side Mongdb Driver is best. Save this answer.
The easiest fix for this;
"npm remove mongoose"
then
"npm install [email protected] --save"
problem solved.
Upgrading is not always the best option.
Help it will help you.
Thanks
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