- 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 commands finds all the documents in the posts collection with post timestamp field as null?
A - db.posts.find( { post_timestamp : { $type: 10 } } )
B - db.posts.find( { post_timestamp: { $type: null } } )
C - db.posts.find( { post_timestamp: { $fieldtype: 10 } } )
D - db.posts.find( { post_timestamp: { $fieldtype: null } } )
Answer : A
Explanation
$type is used for all the operations involving checking the type of a field in MongoDB. 10 represents the BSON value for null.
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 - Consider that you are using { upsert : true } option in your update command. Which of the following parameters will be used to determine if any new documents were inserted:
Answer : D
Explanation
The nUpserted shows the number of documents that were added during the update operation.
Q 5 - You can implement a multi-document transaction in MongoDB using which of the following concept?
Answer : B
Explanation
Operations on a single document are always atomic with MongoDB databases; however, operations that involve multiple documents, which are often referred to as “multi-document transactions”, are not atomic.
Answer : B
Explanation
By default GridFS limits chunk size to 255k.
Answer : B
Explanation
The minimum number of sensible number of voting nodes is 3.
Q 8 - In a replica set, a ________ number of members ensures that the replica set is always able to select a primary.
Answer : A
Explanation
An odd number of members ensures that the replica set is always able to elect a primary. If you have an even number of members, add an arbiter to get an odd number.
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 - 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.