How To Connect Mongodb To Server?
I am trying to get data from mongoDB while connecting to server .i inserted one value in mongoDB like this > use abc switched to db abc > db.ac.insert({name:'naveen'}) Writ
Solution 1:
If you want to display all the documents in the given collection the code should be like this :
MongoClient.connect(url, function(err, db) {
assert.equal(null, err);
var collection = db.collection('ac').find({},function(err,doc){
if(err)
throw err;
else{
console.log(doc);
}
});
console.log("Connected correctly to server.");
db.close();
});
this will print all the documents of collection ac. Otherwise if you directly try to print collection all the metadata will also get printed.
Post a Comment for "How To Connect Mongodb To Server?"