![MongoDB Tutorial](https://www.tutorialspoint.com/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
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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](https://www.tutorialspoint.com/images/questions_and_answers.png)
Q 1 - What kind of database MongoDB is?
Answer : B
Explanation
MongoDB stores data in JSON structure based documents. These documents in turn contains data in form of key value pairs.
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 command can be used to check the size of a collection named posts?
Answer : A
Explanation
To view the statistics for a collection, including the data size, use the db.collection.stats() method from the mongo shell.
Q 4 - What is the output of following two commands in MongoDB:
db.posts.insert({"_id":1})
db.posts.insert({"_id":1})
A - Two documents will be inserted with _id as 1
B - MongoDB will automatically increment the _id of the second document as 2
C - This will throw a duplicate key error
D - It will insert two documents and throw a warning to the user
Answer : C
Explanation
You cannot insert two documents with the same _id field. The value of _id field should be unique.
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.
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 - The following aggregation option is used to specify the specific fields that needs to be passed to the next stage of the aggregation pipeline:
Answer : B
Explanation
The $project operator passes along the documents with only the specified fields to the next stage in the pipeline. The specified fields can be existing fields from the input documents or newly computed fields.
Q 8 - Which of the following aggregate commands in MongoDB uses a pipeline approach with the goals of improving the aggregation performance?
Answer : A
Explanation
The aggregate command in MongoDB is designed with specific goals of improving performance and usability for aggregation tasks. It uses a “pipeline” approach where objects are transformed as they pass through a series of pipeline operators such as $group, $match, and $sort.
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 - Which of the following operator can be used to control the number of items of an array that a query returns?
D - MongoDB does not support partial retrieval of items from an array
Answer : C
Explanation
The $slice operator controls the number of items of an array that a query returns.