Skip to content

Cursors

  • Mongodb returns query results in batches using cursors.
  • Cursor are a pointer to a result set on the server.
  • Default batch size is usually 101 documents.

Cursor Methods

  1. count()
shop> db.products.find().count()
10355
  1. limit()
shop> db.products.find().limit(5)
  1. skip()
shop> db.products.find().limit(5).skip(2)
  1. sort() Price in ascending order
shop> db.products.find().sort({price: 1})

Price in descending order

shop> db.products.find().sort({price: -1})