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
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
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
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
Explanation: MongoDB provides a db.collection.findOne() method as a special case of find() that returns a single document.
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
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
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.
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
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
Explanation: For related projection functionality in the aggregation framework pipeline, use the $project pipeline stage.
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
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
Explanation: For fields that contain arrays, MongoDB provides the following projection operators: $elemMatch, $slice, and $.
Sanfoundry Global Education & Learning Series – MongoDB.
Here’s the list of Best Books in MongoDB.
and Answers.
- Check MongoDB Books
- Apply for Programming Internship
- Check Information Technology Books
- Practice Programming MCQs