Simple example to Connect mongoDB from Node.JS

suggest change
MongoClient.connect('mongodb://localhost:27017/myNewDB',function (err,db) {
    if(err) 
        console.log("Unable to connect DB. Error: " + err)
    else 
        console.log('Connected to DB');

    db.close();
});

myNewDB is DB name, if it does not exists in database then it will create automatically with this call.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents