2016-01-04 59 views

回答

0

要獲得元素的數量在遊標,使用count()方法。在蒙戈外殼,這可以推導如下:

var cursor = db.collection('pages').find({}), 
    numberOfElements = cursor.count(); 

在Node.js的,你可以得到數異步爲:

var numberOfElements = function(db, collectionName, callback){ 
    db.collection(collectionName, function(e, coll) { 
     coll.find({}).count(function (err, count) { 
      if (err) return callback(err); 
      console.log(count); 
      return callback(null, count); 
     }); 
    }); 
}; 
相關問題