简体   繁体   中英

Cant connect to MongoDb

在此处输入图像描述

so this is my code, I watched a lot of videos how to connect mongo db to node and I tried every possible way but it doesnot connect. What's wrong with my code??? also I downloaded every important thing

Your Connection URL is without a port number, add the port number to the URL

mongodb://localhost:27017/subscribers

MongoDB - default port number is 27017

https://docs.mongodb.com/manual/reference/default-mongodb-port/

https://mongoosejs.com/docs/connections.html#connections

You can connect to MongoDB with the mongoose.connect() method.

mongoose.connect('mongodb://localhost:27017/myDB', {useNewUrlParser: true}); 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.

You can also specify several more parameters in the uri:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM