Tuesday, 13 August 2013

How to obtain a MongoDb collection in NodeJS

How to obtain a MongoDb collection in NodeJS

There are two different methods to obtain a reference to a MongoDB
collection - both of them are used throughout the official documentation.
There is
var mycollection = db.collection('mycollection)'
and there is
db.collection('mycollection', function(err, collection){
//use collection
}
I tend to use the second one because it is consistent with
"db.createCollecion(collection, callback)"
What is the difference between these methods?
Is there any database interaction when using these methods?

No comments:

Post a Comment