- 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 MongoDB query is equivalent to the following SQL query:
UPDATE users SET status = "C" WHERE age > 25
A
db.users.update(
{ age: { $gt: 25 } },
{ status: "C" })
B
db.users.update(
{ age: { $gt: 25 } },
{ $set: { status: "C" } })
C
db.users.update(
{ age: { $gt: 25 } },
{ $set: { status: "C" } },
{ multi: true })
D
db.users.update(
{ age: { $gt: 25 } },
{ status: "C" },
{ multi: true })
Answer : C
Explanation
$set is used to set the value of a particular field in a document. The syntax of set is $set:{column_name : column_value}. Also, {multi:true} is needed to update all the documents. Otherwise only the first found document is updated.
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 - In our posts collection, which command can be used to find all the posts whose author names begin lie between “A” and “C” in dictionary order?
A - db.posts.find( { post_author : { $gte : "A" , $lte : "C" } } );
B - db.posts.find( { post_author : { $gte : "C" , $lte : "A" } } );
C - db.posts.find( { post_author : { $gt : "A" , $lt : "C" } } );
Answer : A
Explanation
The $gt, $lt and related operators can be applied for string manipulations too. They work in the same manner as they would work on numeric values.
Q 4 - What does the following query do when performed on the posts collection?
db.posts.update({_id:1},{Title:This is post with ID 1"})
A - Updates the Title of the post
B - Updating a document is possible only with $set
C - Replaces the complete document with _id as 1 with the document specified in second parameter
Answer : C
Explanation
Updating a document without using $set replaces the entire document with whatever document is specified in second parameter.
Q 5 - What does the totalKeysExamined field returned by the explain method indicate?
A - Number of documents that match the query condition
B - Number of index entries scanned
C - Number of documents scanned
D - Details the completed execution of the winning plan as a tree of stages
Answer : B
Explanation
explain.executionStats.totalKeysExamined indicates the number of index entries scanned.
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.
Answer : B
Explanation
The minimum number of sensible number of voting nodes is 3.
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 - 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