简体   繁体   中英

When I try to connect to mongodb in the command prompt it will display an error how to fix it?

events.js:160 throw er; // Unhandled 'error' event

  ^

MongoError: failed to connect to server [localhost:27017] on first connect [MongoError: connect ECONNREFUSED 127.0.0.1:27017]

at Pool.<anonymous> 

(C:\\Users\\DELL\\Desktop\\meanapp\\server\\node_modules\\mongodb-

core\\lib\\topologies\\server.js:328:35)

at emitOne (events.js:96:13)

at Pool.emit (events.js:188:7)

at Connection.<anonymous> 

(C:\\Users\\DELL\\Desktop\\meanapp\\server\\node_modules\\mongodb-

core\\lib\\connection\\pool.js:274:12)

The error is saying that the connection have been refused (ECONNREFUSED). There is no endpoint listening on 127.0.0.1:27017

Mongo have a client-server architecture. Before connecting to the database, you need to start the database server. First, create a folder to store the data files. Then, from command prompt, go to where your mongo installations resides and write:

mongod --port 27017 --dbpath C:\path_to_data_folder

https://docs.mongodb.com/manual/tutorial/manage-mongodb-processes/

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