发布于 2015-09-14 15:11:18 | 92 次阅读 | 评论: 0 | 来源: 网络整理
The db.collection.count() method is a shell wrapper that returns the count of documents that would match a find() query; i.e., db.collection.count() method is equivalent to:
db.collection.find(<query>).count();
This operation does not actually perform the find(); instead, the operation counts the results that would be returned by the find().
The db.collection.count() method can accept the following argument:
参数: |
|
---|
Consider the following examples of the db.collection.count() method
Count the number of all documents in the orders collection:
db.orders.count()
The query is equivalent to the following:
db.orders.find().count()
Count the number of the documents in the orders collection with the field ord_dt greater than new Date('01/01/2012'):
db.orders.count( { ord_dt: { $gt: new Date('01/01/2012') } } )
The query is equivalent to the following:
db.orders.find( { ord_dt: { $gt: new Date('01/01/2012') } } ).count()
也可以参考