MongoDB Questions and Answers – Read Operations – 1

This set of MongoDB Multiple Choice Questions & Answers (MCQs) focuses on “Read Operations – 1”.

1. The order of documents returned by a query is not defined unless you specify a ______
a) sortfind()
b) sortelse()
c) sort()
d) none of the mentioned
View Answer

Answer: c
Explanation: You can modify the query to impose limits, skips, and sort orders.

2. Point out the correct statement.
a) Queries specify criteria, or conditions, that identify the documents that MongoDB returns to the clients
b) Write operations, or queries, retrieve data stored in the database
c) The selection limits the amount of data that MongoDB returns to the client over the network
d) All of the mentioned
View Answer

Answer: a
Explanation: In MongoDB, queries select documents from a single collection.

3. In aggregation pipeline, the _______ pipeline stage provides access to MongoDB queries.
a) $catch
b) $match
c) $batch
d) All of the mentioned
View Answer

Answer: b
Explanation: Operations that modify existing documents (i.e. updates) use the same query syntax as queries to select documents to update.

4. Which of the following method returns one document?
a) findOne()
b) findOne1()
c) selectOne()
d) all of the mentioned
View Answer

Answer: a
Explanation: MongoDB provides a db.collection.findOne() method as a special case of find() that returns a single document.

advertisement
advertisement

5. Point out the wrong statement.
a) sort() modifier sorts the results by age in ascending order
b) Queries in MongoDB return all fields in all matching documents by default
c) To scale the amount of data that MongoDB sends to applications, include a projection in the queries.
d) None of the mentioned
View Answer

Answer: c
Explanation: By projecting results with a subset of fields, applications reduce their network overhead and processing requirements.

6. Which of the following is the second argument to projection?
a) findOne()
b) findOne1()
c) selectOne()
d) find()
View Answer

Answer: d
Explanation: Projections are the second argument to the find() method, which specifies a list of fields to return or list fields to exclude in the result documents.

Note: Join free Sanfoundry classes at Telegram or Youtube

7. Which of the following query selects documents in the records collection that match the condition { “user_id”: { $lt: 42 } }?
a) db.records.findOne( { “user_id”: { $lt: 42 } }, { “history”: 0 } )
b) db.records.find( { “user_id”: { $lt: 42 } }, { “history”: 0 } )
c) db.records.findOne( { “user_id”: { $lt: 42 } }, { “history”: 1 } )
d) db.records.select( { “user_id”: { $lt: 42 } }, { “history”: 0 } )
View Answer

Answer: b
Explanation: Query uses the projection { “history”: 0 } to exclude the history field from the documents in the result set.

8. Which of the following functionality is used for aggregation framework?
a) $match
b) $project
c) $projectmatch
d) All of the mentioned
View Answer

Answer: b
Explanation: For related projection functionality in the aggregation framework pipeline, use the $project pipeline stage.

advertisement

9. To suppress the _id field from the result set, specify _________ in the projection document.
a) _id: 1
b) _id: 0
c) _id: it
d) None of the mentioned
View Answer

Answer: b
Explanation: By default, the _id field is included in the results.

10. Which of the following is not a projection operator?
a) $slice
b) $elemMatch
c) $
d) None of the mentioned
View Answer

Answer: d
Explanation: For fields that contain arrays, MongoDB provides the following projection operators: $elemMatch, $slice, and $.

advertisement

Sanfoundry Global Education & Learning Series – MongoDB.

Here’s the list of Best Books in MongoDB.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.