- 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 - In a collection that contains 100 post documents, what does the following command do?
db.posts.find().skip(5).limit(5)
A - Skip and limit nullify each other. Hence returning the first five documents.
B - Skips the first five documents and returns the sixth document five times
C - Skips the first five documents and returns the next five
D - Limits the first five documents and then return them in reverse order
Answer : C
Explanation
The skip and limit functions are applies linearly and hence it will first skip documents 1-5, and then return documents 6-10.
Q 2 - Within how much time does MongDB writes are written to the journal?
Answer : B
Explanation
Writes are physically written to the journal within 100 milliseconds, by default.
Q 3 - Consider that our posts collection contains an array field called tags that contains tags that the user enters.
{
_id: 1,
tags: [tutorial, fun, learning],
post_text: This is my first post,
//other elements of document
}
Which of the following commands will find all the posts that have been tagged as tutorial.
A - db.posts.find( { tags : "tutorial" } );
B - db.posts.find( { tags : ["tutorial"] } );
Answer : A
Explanation
Searching an array is no different than searching a normal field. Hence the first option.
Q 4 - Which option can be used with update command so that a new document gets created if no matching document is found based on the query condition?
A - Specify {upsert : true } as the third parameter of update command
B - upsert command instead of update command
C - {update: true, insert: true} as the third parameter of update command
Answer : A
Explanation
When you specify upsert: true for an update operation and no matching documents are found, MongoDB creates a new document.
Q 5 - Which of the following operator can be used to limit the number of documents in an array field of a document after an update is performed?
Answer : A
Explanation
You can iterate over all the array elements using $each, slice them using $slice and then push them back to the document using $push.
Q 6 - What is the equivalent command in MongoDB for the following SQL query?
SELECT * FROM posts WHERE author like "%john%"
A - db.posts.find( { author: /john/ } )
B - db.posts.find( { author: {$like: /john/} } )
Answer : A
Explanation
db.posts.find( { author: /john/ } )
Q 7 - The following aggregation option is used to specify the specific fields that needs to be passed to the next stage of the aggregation pipeline:
Answer : B
Explanation
The $project operator passes along the documents with only the specified fields to the next stage in the pipeline. The specified fields can be existing fields from the input documents or newly computed fields.
Q 8 - Given the following posts document:
{
"_id" : 1,
"post_text" : "This post does not matter,
tags: [ "tutorial", "fun", "learning"],
// rest of the document
}
What will be the output of following query:
db.posts.aggregate( [ { $unwind : "$tags" } ] )
A - Return three separate documents for three separate tags
B - Arranges the tags (wind) in ascending order
C - Arranges the tags (wind) in descending order
D - Returns one document but converts the tags array in an object
Answer : A
Explanation
Deconstructs an array field from the input documents to output a document for each element. Each output document is the input document with the value of the array field replaced by the element.
Q 9 - The oplog (operations log) is a special capped collection that keeps a rolling record of all operations that modify the data stored in your databases. All the replica set members contain a copy of the oplog in the following collection:
Answer : B
Explanation
All replica set members contain a copy of the oplog, in the local.oplog.rs collection, which allows them to maintain the current state of the database.
Q 10 - The _______ operator can be used to identify an element in the array to be updated without explicitly specifying the position of the element.
D - Updating an array field without knowing its index is not possible.
Answer : A
Explanation
The positional $ operator identifies an element in an array to update without explicitly specifying the position of the element in the array.