nerdexam
MongoDB

C100DBA · Question #43

In a collection that contains 100 post documents, what does the following command do? db. posts. find().skip(5).limit(5)

The correct answer is B. Skips the first five documents and returns the next five. db.posts.find().skip(5).limit(5) chains two cursor modifiers: skip(5) bypasses the first 5 documents, then limit(5) returns the next 5 - making B correct, yielding documents 6 through 10. Why the distractors fail: A is wrong because skip and limit don't cancel each other - they c

MongoDB Fundamentals

Question

In a collection that contains 100 post documents, what does the following command do? db. posts. find().skip(5).limit(5)

Options

  • ASkip and limit nullify each other. Hence returning the first five documents.
  • BSkips the first five documents and returns the next five
  • CLimits the first five documents and then return them in reverse order
  • DSkips the first five documents and returns the sixth document five times

How the community answered

(41 responses)
  • A
    2% (1)
  • B
    93% (38)
  • C
    5% (2)

Explanation

db.posts.find().skip(5).limit(5) chains two cursor modifiers: skip(5) bypasses the first 5 documents, then limit(5) returns the next 5 - making B correct, yielding documents 6 through 10.

Why the distractors fail:

  • A is wrong because skip and limit don't cancel each other - they compose sequentially.
  • C is wrong because limit caps the result count; it has no concept of reversing order.
  • D is wrong because skip moves the cursor start position once - it doesn't duplicate any single document.

Memory tip: Think of it like a book - skip(5) turns past the first 5 pages, then limit(5) lets you read only the next 5. The two methods work together for pagination, not against each other.

Topics

#skip#limit#cursor methods#pagination

Community Discussion

No community discussion yet for this question.

Full C100DBA Practice