Node.js connect to MongoDB throw an error :MongoError: failed to connect to server [127.0.0.1:27017] on first connect -


i trying use node.js connect mongodb on windows system. however, throw me error:

c:\users\mazic\dropbox\information system\cs602 server site web development\mongodb_practice\node_modules\mongodb\lib\mongo_client.js:225           throw err           ^ mongoerror: failed connect server [127.0.0.1:27017] on first connect     @ null.<anonymous> (c:\users\mazic\dropbox\information system\cs602 server site web development\mongodb_practice\node_modules\mongodb\node_modules\mongodb-core\lib\topologies\server.js:313:35)     @ emitone (events.js:77:13)     @ emit (events.js:169:7)     @ null.<anonymous> (c:\users\mazic\dropbox\information system\cs602 server site web development\mongodb_practice\node_modules\mongodb\node_modules\mongodb-core\lib\connection\pool.js:260:12)     @ g (events.js:260:16)     @ emittwo (events.js:87:13)     @ emit (events.js:172:7)     @ socket.<anonymous> (c:\users\mazic\dropbox\information system\cs602 server site web development\mongodb_practice\node_modules\mongodb\node_modules\mongodb-core\lib\connection\connection.js:162:49)     @ socket.g (events.js:260:16)     @ emitone (events.js:77:13) 

and here code:

"use strict"; const mongoclient = require('mongodb').mongoclient;  const dburl = 'mongodb://127.0.0.1:27017/cs602';  mongoclient.connect(dburl,  (err, db) => {     if (err)     {throw err}else {         console.log('successfully connected to',             db.s.databasename);     }     // database operations     db.close(); }); 

here file structure: enter image description here

i new node.js mongodb, can me this? thank in advance!

this error caused mongodb's bind ip setting. can check mongodb's config file. truth don't know located in windows systems.

in case, bind ip set localhost address, following:

# /usr/local/etc/mongod.conf net:   bindip: 127.0.0.1 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -