发布于 2015-09-14 15:11:18 | 82 次阅读 | 评论: 0 | 来源: 网络整理

db.collection.count()

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:

参数:
  • query (document) – Specifies the selection query criteria.

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()
    

也可以参考

cursor.count()

最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务