C100DBA practice question 6 of 25
Which of the following is incorrect statement about find and findOne operations in MongoDB?
Full set: 130 questionsThe statement that both find() and findOne() return cursors is incorrect. The db.collection.find() method returns a cursor object, which points to the result set of a query. The client application can then iterate through the cursor to retrieve the documents. In contrast, the db.collection.findOne() method executes a search for a single document and returns that one document object directly, not a cursor. This makes findOne() a more direct way to retrieve a single record.
A. This statement is functionally correct; find() is used to get multiple documents (via a cursor) and findOne() gets the first one.
B. This is a correct statement. find().limit(1) returns a cursor, whereas findOne() returns a document object, making their return types different.
C. This is a correct statement. findOne() retrieves and returns the first document that matches the query criteria based on the natural order or a specified sort order.
1. MongoDB Manual, "db.collection.findOne()". The documentation explicitly states, "Returns one document that satisfies the specified query criteria on the collection or view." The return value is described as a document.
2. MongoDB Manual, "db.collection.find()". The documentation states, "Selects documents in a collection or view and returns a cursor to the selected documents."
3. MongoDB University, M001: MongoDB Basics, "findOne vs find". The course material distinguishes between the two methods, highlighting that find() returns a cursor that can be iterated, while findOne() returns the document itself.
Keep practicing
Take the free C100DBA practice test
Ten exam-style questions with answers and explanations, plus the exam facts and study guides.
More questions
Other C100DBA practice questions
- Question 1If the value of totalKeysExamined is 30000 and the value of totalDocsExamined is 0, which…
- Question 2The oplog (operations log) is a special capped collection that keeps a rolling record of …
- Question 3‘$set' sets the value of
- Question 4What does the totalKeysExamined field returned by the explain method indicate?
- Question 5Which mongodb tools allow us to work with our data in a human readable format?
- Question 7In a sharded replicas set environment with multiple mongos servers, which of the followin…
