- 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 correct explanation of MongoDB processes?
A - mongod.exe is the shell process and mongo.exe is the actual database process
B - mongo.exe is the shell process and mongod.exe is the actual database process
C - mongos.exe is the MongoDB server process needed to run database
D - mongodump.exe can be used to import database backup dump
Answer : B
Explanation
The core components in the MongoDB package are: mongod, the core database process; mongos the controller and query router for sharded clusters; and mongo the interactive MongoDB Shell.
Q 2 - Which of the following is true about sharding?
A - Sharding is enabled at the database level
B - Creating a sharded key automatically creates an index on the collection using that key
C - We cannot change a shard key directly/automatically once it is set up
Answer : C
Explanation
There is no direct way of changing the sharded key unless you dump the entire data, drop the sharded key and then re-import everything. Other all options are false. Sharding is enabled at collection level, it does not create any index by default and finally sharding environment supports regular sorting.
Q 3 - Which of the following commands can cause the database to be locked?
Answer : D
Explanation
All the above commands wither result in a read lock or a write lock or both.
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 - 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 - 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 - Consider that you have a collection called population which has fields state and city. Which of the following query will calculate the population grouped by state and city?
Answer : A
Explanation
You have to give state and city as the key to group by and then calculate the sum of the population in each city.
Q 8 - What is a replica set node which does not maintain its own data but exists only for voting purpose called?
Answer : B
Explanation
We may add an extra mongod instance to a replica set as an arbiter. Arbiters do not maintain a data set. Arbiters only exist to vote in elections. If your replica set has an even number of members, add an arbiter to obtain a majority of votes in an election for primary. Arbiters do not require dedicated hardware
Q 9 - Consider that you have the following two documents in the products collection:
{ "_id" : 1, "prices" : [ 60, 100, 200 ] }
{ "_id" : 2, "prices" : [ 20, 90, 150 ] }
What will the following query result into:db.products.update( { _id: 1, prices: 100 }, { $set: { "prices.$" : 111 } } )
C - Updates 60,100 and 200 to 111
D - Removes the three elements of the prices array and replaces it with only a single element 111
Answer : B
Explanation
The positional $ operator identifies an element in an array to update without explicitly specifying the position of the element in the array. To project, or return, an array element from a read operation, see the $ projection operator.
Q 10 - Consider the following document from the products collection:
{ _id: 1, product_code: "345678", variations: [ { size: "L", price: 1000 }, { size: "M", price: 800 } ] }
What does the following query using $elemMatch return?
db.products.find( { product_code: "345678" }, { variations: { $elemMatch: { size: “L” } } } )
A - Returns the complete document since MongoDB does not support partial array retrieval
B - Returns the document but with only one element in the variations array (corresponding to size L)
C - Returns the complete document but retrieves only the size field from the array
Answer : B
Explanation
The $elemMatch operator limits the contents of an <array> field from the query results to contain only the first element matching the $elemMatch condition.
To Continue Learning Please Login
Login with Google