- MongoDB - Home
- MongoDB - Overview
- MongoDB - Advantages
- MongoDB - Environment
- MongoDB - Data Modeling
- MongoDB - Create Database
- MongoDB - Drop Database
- MongoDB - Create Collection
- MongoDB - Drop Collection
- MongoDB - Data Types
- MongoDB - Insert Document
- MongoDB - Query Document
- MongoDB - Update Document
- MongoDB - Delete Document
- MongoDB - Projection
- MongoDB - Limiting Records
- MongoDB - Sorting Records
- MongoDB - Indexing
- MongoDB - Aggregation
- MongoDB - Replication
- MongoDB - Sharding
- MongoDB - Create Backup
- MongoDB - Deployment
- MongoDB - Java
- MongoDB - PHP
- MongoDB - Relationships
- MongoDB - Database References
- MongoDB - Covered Queries
- MongoDB - Analyzing Queries
- MongoDB - Atomic Operations
- MongoDB - Advanced Indexing
- MongoDB - Indexing Limitations
- MongoDB - ObjectId
- MongoDB - Map Reduce
- MongoDB - Text Search
- MongoDB - Regular Expression
- Working with Rockmongo
- MongoDB - GridFS
- MongoDB - Capped Collections
- Auto-Increment Sequence
MongoDB Online Quiz
Following quiz provides Multiple Choice Questions (MCQs) related to MongoDB Framework. You will have to read all the given answers and click over the correct answer. If you are not sure about the answer then you can check the answer using Show Answer button. You can use Next Quiz button to check new set of questions in the quiz.
Q 1 - A collection and a document in MongoDB is equivalent to which of the SQL concepts respectively?
Answer : A
Explanation
The way SQL databases stores data rows in a table, MonngoDB stores documents inside collections.
Q 2 - Which of the following replica sets vote in the election of a primary replica set?
Answer : D
Explanation
All members of a replica set, unless the value of votes is equal to 0, vote in elections. This includes all delayed, hidden and secondary-only members.
Q 3 - By default, the MongoDB cursor in mongo shell is configured to return how many documents? To get the next set of documents, which command is used?
Answer : A
Explanation
In the mongo shell, if the returned cursor is not assigned to a variable using the var keyword, then the cursor is automatically iterated up to 20 times [1] to print up to the first 20 documents in the results. To get the next set of results, you should use it command which will iterate over the next set of results.
Q 4 - Consider that the posts collection contains an array called ratings which contains ratings given to the post by various users in the following format:
{
_id: 1,
post_text: This is my first post,
ratings: [5, 4, 2, 5],
//other elements of document
}
Which of the following query will return all the documents where the ratings array contains elements that in some combination satisfy the query conditions?
A - db.inventory.find( { ratings: { $elemMatch: { $gt: 3, $lt: 6 } } } )
B - db.inventory.find( { ratings: { ratings: { $gt: 5, $lt: 9 } } } )
C - db.inventory.find( { ratings: { ratings.$: { $gt: 5, $lt: 9 } } } )
D - db.inventory.find( { ratings: { $elemMatch: { $gte: 3, $lte: 6 } } } )
Answer : B
Explanation
This query will check if the array elements match the given condition in some or the other way or combination.
Q 5 - Which option should be used with findAndModify() command to return the modified document instead of the pre-modification document?
A - findAndModify by default returns the pre-modification document
C - Use the POST version of findAndModify called findAndModifyPost
Answer : B
Explanation
When true, returns the modified document rather than the original. The findAndModify() method ignores the new option for remove operations. The default is false.
Q 6 - Update If Correct is an approach for which of the following concepts in MongoDB:
Answer : A
Explanation
The Update if Current pattern is an approach to concurrency control when multiple applications have access to the data.
Q 7 - In a sharded replica set environment, the w Option provides ability for write concern and j Option provides ability for the data to be written on disk journal. Consider that we have a seven member replica set and we want to assure that the writes are committed to journal. What should be the value of j?
Answer : B
Explanation
To enable the disk journaling commits, j value should always be set to 1.
Q 8 - Which of the following SQL terminology is same as $match in MongoDB?
Answer : C
Explanation
In MongoDB, we use $match as the aggregation operator corresponding to WHERE and HAVING condition in MongoDB.
Q 9 - We can insert multiple documents in bulk using which of the following operations:
Answer : A
Explanation
The initializeUnorderedBulkOp operation returns an unordered operations builder which maintains a list of operations to perform. Unordered operations means that MongoDB can execute in parallel as well as in nondeterministic order.
Q 10 - What does the following $slice query return using the following command?
db.posts.find( {}, { comments: { $slice: [ -10, 5 ] } } )
A - Returns 5 comments, beginning with the last 10 items
B - Returns 10 comments, beginning with the first
Answer : A
Explanation
The $slice operation selects the document collection identified by a field named field that holds value and returns the number of elements specified by the value of count from the array stored in the array field.