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…
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)- A6% (3)
- B2% (1)
- C2% (1)
- D90% (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, whilefindOne()stops at the first match. - B is true:
find().limit(1)still returns a cursor (you must iterate it), whereasfindOne()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
Community Discussion
No community discussion yet for this question.