0
votes

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)

1
Have you started the MongoD Service before connecting? - Oscar
nope I write the following code mongose.connect('mongodb://localhost/meanapp'); mongose.connection.once('open',function() { //Load the models console.log('Listening on port 3000...'); app.listen(3000); }); - Joan
nope I just write the code as //Connect to MongoDB mongose.connect('mongodb://localhost/meanapp'); mongose.connection.once('open',function() { //Load the models console.log('Listening on port 3000...'); app.listen(3000); }); - Joan

1 Answers

0
votes

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/