nerdexam
MongoDB

C100DBA · Question #54

Which of the following is incorrect statement about find and findOne operations in MongoDB?

The correct answer is D. findQ and findOneQ returns cursors to the collection documents. D is incorrect because findOne() does not return a cursor - it returns the actual document object directly (or null if nothing matches). Only find() returns a cursor, so claiming both return cursors is the false statement. Why A, B, and C are correct (and therefore not the…

MongoDB Fundamentals

Question

Which of the following is incorrect statement about find and findOne operations in MongoDB?

Options

  • AfindQ returns all the documents in a collection while findOne() retrieves only the first one.
  • Bfind.limit(l) is not the same query as findOne()
  • CfindOneQ returns the actual first document retrieved from a collection
  • DfindQ and findOneQ returns cursors to the collection documents

How the community answered

(50 responses)
  • A
    6% (3)
  • B
    2% (1)
  • C
    2% (1)
  • D
    90% (45)

Explanation

D is incorrect because findOne() does not return a cursor - it returns the actual document object directly (or null if nothing matches). Only find() returns a cursor, so claiming both return cursors is the false statement.

Why A, B, and C are correct (and therefore not the answer):

  • A is true: find() retrieves all matching documents via a cursor, while findOne() stops at the first match.
  • B is true: find().limit(1) still returns a cursor (you must iterate it), whereas findOne() returns the document itself - different behavior, not equivalent.
  • C is true: findOne() hands back the raw document object, not a cursor, which is precisely what makes D false.

Memory tip: Think of find() as handing you a pointer to a shelf (cursor - you browse it yourself), while findOne() hands you the book directly. If both gave you a pointer, there'd be no reason for findOne() to exist.

Topics

#find#findOne#cursor#query methods

Community Discussion

No community discussion yet for this question.

Full C100DBA Practice