Skip to content

Latest commit

 

History

History
33 lines (18 loc) · 1.07 KB

04_Sort-Limit.md

File metadata and controls

33 lines (18 loc) · 1.07 KB

Sort and Limit Data

  1. limit db.people.find().limit(2)

image

Use : It is used in Pagination Pagination is a technique used in database queries (and in web applications generally) to divide a large dataset into smaller, more manageable chunks or "pages." This allows users to retrieve and view a portion of the data at a time rather than loading the entire dataset in a single query.

  • Achieving pagination using Mongodb find and limit

image

  1. Skip : skips the specified number of documents db.people.find().skip(1)

image

3.sort db.people.find().sort({age:1})

1 → ascending order

image

db.people.find().sort({age: -1})

-1 → descending order

image