Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

connecting to Mongo DB with mongoose version (4.11.0) [duplicate]

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!

like image 487
ZABA Avatar asked Jun 28 '17 08:06

ZABA


People also ask

Can you use mongoose and MongoDB together?

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.

How do we connect mongoose to our MongoDB database?

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 .

Should I use MongoDB driver or mongoose?

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.


1 Answers

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

like image 178
Alex Avatar answered Sep 20 '22 02:09

Alex