- MongoDB Tutorial
- 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
- Advanced MongoDB
- 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 Useful Resources
- MongoDB - Questions and Answers
- MongoDB - Quick Guide
- MongoDB - Useful Resources
- MongoDB - Discussion
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 - Which of the following is a valid MongoDB JSON document:
B
{
"user_id"=1,
"user_name"="Joe Sanders",
"occupation"=["engineer","writer"]
}
C
{
"user_id":1;
"user_name":"Joe Sanders";
"occupation":["engineer","writer"]
}
Answer : A
Explanation
A blank document is valid in MongoDB. However, rest of the three documents have some or the other problem. Option b has “=”, Option c has “;” and Option d has an incorrect array format. It should be a sub-document instead.
Q 2 - Which of the following command can be used in mongo shell to show all the databases in your MongoDB instance?
Answer : A
Explanation
show dbs returns the list of all the databases.
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 - Which of the following commands removes a single document that matches the condition that Author is Joe?
A - db.posts.removeOne( { Author : "Joe" }, 1 )
B - db.posts.remove( { Author : "Joe" }, 1 )
Answer : D
Explanation
The third parameter to the remove function is justOne. You can either simply say 1 or write justOne as true.
Answer : A
Explanation
MongoDB is written in C++.
Q 6 - Which of the following collections are used by MongoDB to store GridFS data?
Answer : A
Explanation
GridFS stores files in two collections: chunks stores the binary chunks and files stores the file’s metadata.
Q 7 - What does the output x of the following MongoDB aggregation query result into:
db.posts.aggregate( [ { $group: { _id: "$author", x: { $sum: “$likes” } } } ] )A - Average of likes on all the posts of an author, grouped by author
B - Number of posts by an author
C - Sum of likes on all the posts by an author, grouped by author
Answer : C
Explanation
The above query first does a grouping on author field and then calculates the number of likes on all the posts that were grouped together.
Q 8 - Given a collection posts as shown below having a document array comments, which of the following command will create an index on the comment author descending?
{ “_id”:1, “post_text”:”This is a sample post”, “author”:”Tom”, “comments”:[ { “author”:”Joe”, “comment_text”:”This is comment 1” }, { “author”:”Leo”, “comment_text”:”This is comment 2” } ] }
A - db.posts.createIndex({“comments.$.author":-1});
B - db.posts.createIndex({“comments.author":-1});
C - db.posts.createIndex({“comments.author":1});
D - db.posts.createIndex({“comments.$.author": {“$desc”:1}});
Answer : B
Explanation
We can access the document fields within an array using dot notation. And for indicating the index sorting, we just have to mention 1 or -1.
Q 9 - The difference between $push and $addToSet is:
A - $addToSet adds the item to the field only if the new item is of the same datatype
D - There is no major difference between them. $addToSet is a deprecated version of $push.
Answer : C
Explanation
$addToSet do not add the item to the given field if it already contains it, on the other hand $push will add the given object to field whether it exists or not.
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.