![MongoDB Tutorial](/mongodb/images/mongodb-mini-logo.jpg)
- 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.
![Questions and Answers](/images/questions_and_answers.png)
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 replica sets vote in the election of a primary replica set?
Answer : D
Explanation
All members of a replica set, unless the value of votes is equal to 0, vote in elections. This includes all delayed, hidden and secondary-only members.
Q 3 - Which of the following is the most important consideration while designing the schema for MongoDB?
A - The schema should match the data access and query patterns
B - The schema should be kept in 3NF similar to SQL schemas
C - The schema should focus on creating possible embedded documents
Answer : A
Explanation
The efficiency of a MongoDB database depends on how well the database is designed depending on the application usage. The schema should be designed based on how the data access patterns are.
Q 4 - Which option can be used with update command so that a new document gets created if no matching document is found based on the query condition?
A - Specify {upsert : true } as the third parameter of update command
B - upsert command instead of update command
C - {update: true, insert: true} as the third parameter of update command
Answer : A
Explanation
When you specify upsert: true for an update operation and no matching documents are found, MongoDB creates a new document.
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.
Answer : B
Explanation
By default GridFS limits chunk size to 255k.
Q 7 - In a sharded replica set environment, the w Option provides ability for write concern and j Option provides ability for the data to be written on disk journal. Consider that we have a seven member replica set and we want to assure that the writes are committed to journal. What should be the value of j?
Answer : B
Explanation
To enable the disk journaling commits, j value should always be set to 1.
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 - Which of the following is the correct syntax for starting a new mongod process and specifying its replica set name as rs0:
D - First execute this: mongod --replSet. And then execute this: rs.add()
Answer : A
Explanation
Replica set can be set/stated using the –replSet command and specifying the replica name with it.
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.
To Continue Learning Please Login