Limiting results in MongoDB but still getting the full count?

后端 未结 5 490
不思量自难忘°
不思量自难忘° 2020-12-03 09:38

For speed, I\'d like to limit a query to 10 results

db.collection.find( ... ).limit(10)

However, I\'d also like to know the total count, so

5条回答
  •  一向
    一向 (楼主)
    2020-12-03 10:12

    cursor.count() should ignore cursor.skip() and cursor.limit() by default.

    Source: http://docs.mongodb.org/manual/reference/method/cursor.count/#cursor.count

提交回复
热议问题