发布于 2015-09-14 14:47:17 | 163 次阅读 | 评论: 0 | 来源: 网络整理

cursor.count()

The count() method counts the number of documents referenced by a cursor. Append the count() method to a find() query to return the number of matching documents, as in the following prototype:

db.collection.find().count()

This operation does not actually perform the find(); instead, the operation counts the results that would be returned by the find().

The count() can accept the following argument:

参数:

MongoDB also provides the shell wrapper db.collection.count() for the db.collection.find().count() construct.

Consider the following examples of the count() method:

  • Count the number of all documents in the orders collection:

    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.find( { ord_dt: { $gt: new Date('01/01/2012') } } ).count()
    
  • Count the number of the documents in the orders collection with the field ord_dt greater than new Date('01/01/2012') taking into account the effect of the limit(5):

    db.orders.find( { ord_dt: { $gt: new Date('01/01/2012') } } ).limit(5).count(true)
    
最新网友评论  共有(0)条评论 发布评论 返回顶部

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