sort, limit and skip

noun

say it: “SORT, LIM-it and SKIP” /ˈsɔrt ˈlɪmɪt ənd ˈskɪp/

MongoDB cursor methods: sort puts results in order, limit caps how many come back, and skip jumps over some, which together give pages.

What does sort, limit and skip do?

sort orders results (1 ascending, -1 descending), limit caps how many come back, and skip jumps over some for paging.

db.recipes.find().sort({ rating: -1 }).skip(20).limit(10)

In a sentence

  • “sort, limit and skip give page 2: sort by name, skip 10, limit 10.”
  • “Use sort, limit and skip together, always with a sort, or pages can repeat documents.”

Level: Apprentice · More MongoDB terms at this level

Updated