- 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 - Which of the following is supported by MongoDB?
B - Relationships between Collections (Primary Key Foreign Key)
Answer : C
Explanation
MongoDB does not support things like ACID Transactions or atomicity across collections or relationships like SQL.
Q 4 - What does the following query do when performed on the posts collection?
db.posts.update({_id:1},{$set:{Author:Tom"}})
B - Adds a new field Author in the searched collection if not already present
C - Updates only the Author field of the document with _id as 1
Answer : D
Explanation
$set sets the specific fields in the matched documents or adds them as a new field if not already present.
Q 5 - Consider the following posts document:
{
_id: 1,
post_text: This is my first post,
author: Tom,
tags: [tutorial,quiz,facebook,learning,fun]
}
Which of the following queries will return the documents but with only the first two tags in the tags array?
A - db.posts.find({author:"Tom"},{tags:{$slice:2}})
B - db.posts.find({author:"Tom"}).limit({tags:2})
C - db.posts.find({author:"Tom"}).limit($slice:{tags:2})
D - Both a and c are valid. $slice works both with projection and limit.
Answer : A
Explanation
The $slice operator controls the number of items of an array that a query returns.
Q 6 - Which of the following about Capped Collections is correct?
B - If the allocated space for a capped collection exceeds, it stops inserting new documents
C - High-throughput operations that insert and retrieve documents based on insertion order
Answer : D
Explanation
Capped collections are fixed-size collections that support high-throughput operations that insert and retrieve documents based on insertion order. Capped collections work in a way similar to circular buffers: once a collection fills its allocated space, it makes room for new documents by overwriting the oldest documents in the collection.
Q 7 - What does the following aggregate query perform?
db.posts.aggregate( [
{ $match : { likes : { $gt : 100, $lte : 200 } } },
{ $group: { _id: null, count: { $sum: 1 } } }
] );
A - Calculates the number of posts with likes between 100 and 200
B - Groups the posts by number of likes (101, 102, 103.) by adding 1 every time
C - Fetches the posts with likes between 100 and 200 and sets their _id as null
Answer : A
Explanation
The above query basically matches all the documents having likes between 100 and 200. After that, it just specifies that aggregation is not to be done with any specific column (_id:null) and increments the count every time. Thus calculating the total such posts.
Q 8 - Which of the following aggregate commands in MongoDB uses a pipeline approach with the goals of improving the aggregation performance?
Answer : A
Explanation
The aggregate command in MongoDB is designed with specific goals of improving performance and usability for aggregation tasks. It uses a pipeline approach where objects are transformed as they pass through a series of pipeline operators such as $group, $match, and $sort.
Q 9 - Which of the following aggregation query will sort the posts collection with author key ascending:
A - db.posts.aggregate([ {$sort:{ author:1 } } ])
B - db.posts.aggregate([ {$sort:{ author:-1 } } ])
C - db.posts.aggregate([ {author: {$sort: 1} } ])
D - You need to first use $group or $project or $match command before $sort in the pipeline
Answer : A
Explanation
In the aggregation pipeline, it is not necessary to have a $group or $project or $match before the $sort operation.
Q 10 - Which index is used to index the content stored in arrays?
Answer : A
Explanation
MongoDB uses multikey indexes to index the content stored in arrays. If you index a field that holds an array value, MongoDB creates separate index entries for every element of the array.