I'm trying to iterate a MongoDB collection and convert it into a list. But the array list is always empty. Here is the code:
var MongoClient = require('mongodb').MongoClient;
getPost: function(callback){
MongoClient.connect(url, function(err, db){
var cursor = db.collection('post').find();
var list = [];
cursor.forEach(function(doc){
list.push(doc);
});
callback(list);
})
}
list
is always []
.
via iJade
No comments:
Post a Comment