- 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 Mock Test
This section presents you various set of Mock Tests related to MongoDB Framework. You can download these sample mock tests at your local machine and solve offline at your convenience. Every mock test is supplied with a mock test key to let you verify the final score and grade yourself.
MongoDB Mock Test III
Q 1 - Update If Correct is an approach for which of the following concepts in MongoDB:
Answer : A
Explanation
The Update if Current pattern is an approach to concurrency control when multiple applications have access to the data.
Q 2 - Which of the following about Capped Collections is correct?
B - If the allocated space for a capped collection exceeds, it stops inserting new documents
C - High-throughput operations that insert and retrieve documents based on insertion order
Answer : D
Explanation
Capped collections are fixed-size collections that support high-throughput operations that insert and retrieve documents based on insertion order. Capped collections work in a way similar to circular buffers: once a collection fills its allocated space, it makes room for new documents by overwriting the oldest documents in the collection.
Q 3 - Which of the following is not a system collection in MongoDB?
Answer : D
Explanation
There is no system collection to store database preferences.
Q 4 - 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 5 - For capped collection, cursors which do not automatically close and remain open after the client exhausts the results are called:
Answer : B
Explanation
By default, MongoDB will automatically close a cursor when the client has exhausted all results in the cursor. However, for capped collections you may use a Tailable Cursor that remains open after the client exhausts the results in the initial cursor.
Answer : B
Explanation
By default GridFS limits chunk size to 255k.
Q 7 - 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 8 - Which is the correct order (lowest to highest) in which MongoDB compares the BSON types?
A - Null, Number, String and Object
B - Number, Null, String and Object
Answer : A
Explanation
This is the defined order in which the bson types are compared. There are various other fields as per the BSON specification which can be found here: http://docs.mongodb.org/manual/reference/bson-types/
Q 9 - As per the aggregation pipeline optimization concepts, if you have a $sort followed by a $match:
C - MongoDB does not do any movements by default and will use the order provided
D - Providing these parameters in any order does not impact the performance
Answer : A
Explanation
When you have a sequence with $sort followed by a $match, the $match moves before the $sort to minimize the number of objects to sort.
Q 10 - Aggregation Pipelines have a limit of:
A - 2 MB document and 100 MB RAM
B - 16 MB document and 100 MB RAM
Answer : B
Explanation
Pipeline stages have a limit of 100 megabytes of RAM. If a stage exceeds this limit, MongoDB will produce an error. If the aggregate command returns a single document that contains the complete result set, the command will produce an error if the result set exceeds the BSON Document Size limit, which is currently 16 megabytes.
Q 11 - Which of the following methods can be used in MongoDB for relation documents?
Answer : C
Explanation
Manual references where you save the _id field of one document in another document as a reference. DBRefs are references from one document to another using the value of the first document’s _id field, collection name, and, optionally, its database name.
Q 12 - Which of the following command inside aggregate command is used in MongoDB aggregation to filter the documents to pass only the documents that match the specified condition(s) to the next pipeline stage.
Answer : B
Explanation
$match filters the documents to pass only the documents that match the specified condition(s) to the next pipeline stage.
Q 13 - What does the following aggregate query perform?
db.posts.aggregate( [ { $match : { likes : { $gt : 100, $lte : 200 } } }, { $group: { _id: null, count: { $sum: 1 } } } ] );
A - Calculates the number of posts with likes between 100 and 200
B - Groups the posts by number of likes (101, 102, 103….) by adding 1 every time
C - Fetches the posts with likes between 100 and 200 and sets their _id as null
Answer : A
Explanation
The above query basically matches all the documents having likes between 100 and 200. After that, it just specifies that aggregation is not to be done with any specific column (_id:null) and increments the count every time. Thus calculating the total such posts.
Q 14 - What does the output x of the following MongoDB aggregation query result into:
db.posts.aggregate( [ { $group: { _id: "$author", x: { $sum: “$likes” } } } ] )A - Average of likes on all the posts of an author, grouped by author
B - Number of posts by an author
C - Sum of likes on all the posts by an author, grouped by author
Answer : C
Explanation
The above query first does a grouping on author field and then calculates the number of likes on all the posts that were grouped together.
Q 15 - 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 16 - What is the minimum sensible number of voting nodes to a replica set?
Answer : B
Explanation
The minimum number of sensible number of voting nodes is 3.
Q 17 - 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 18 - 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 as well as acknowledged by at least 3 nodes. What should be the value of w?
Answer : C
Explanation
The value of w determines the writes are committed and acknowledged by some minimum number of nodes which in this case is 3.
Q 19 - In a sharded replicas set environment with multiple mongos servers, which of the following would decide the mongos failover?
Answer : C
Explanation
Since the mongos are itself failing in this case, this logic has to be built on the drivers side.
Q 20 - 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 21 - 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 22 - Which of the following command is used to get all the indexes on a collection?
A - db.collection.getIndexes()
B - db.collection.showIndexes()
Answer : A
Explanation
db.collection.getIndexes() is the correct choice.
Q 23 - Given a collection posts as shown below having a document array comments, which of the following command will create an index on the comment author descending?
{ “_id”:1, “post_text”:”This is a sample post”, “author”:”Tom”, “comments”:[ { “author”:”Joe”, “comment_text”:”This is comment 1” }, { “author”:”Leo”, “comment_text”:”This is comment 2” } ] }
A - db.posts.createIndex({“comments.$.author":-1});
B - db.posts.createIndex({“comments.author":-1});
C - db.posts.createIndex({“comments.author":1});
D - db.posts.createIndex({“comments.$.author": {“$desc”:1}});
Answer : B
Explanation
We can access the document fields within an array using dot notation. And for indicating the index sorting, we just have to mention 1 or -1.
Q 24 - Which of the following commands create an unique index on author field of the posts collection?
A - db.posts.createIndex({"author":1 }, {"unique": true});
B - db.posts.createIndex({"author": unique });
Answer : A
Explanation
MongoDB cannot create a unique index on the specified index field(s) if the collection already contains data that would violate the unique constraint for the index. The syntax for the same is db.collection.createIndex( { a: 1 }, { unique: true } )
Q 25 - Which of the following SQL terminology is same as $match in MongoDB?
Answer : C
Explanation
In MongoDB, we use $match as the aggregation operator corresponding to WHERE and HAVING condition in MongoDB.
Answer Sheet
Question Number | Answer Key |
---|---|
1 | A |
2 | D |
3 | D |
4 | A |
5 | B |
6 | B |
7 | A |
8 | A |
9 | A |
10 | B |
11 | C |
12 | B |
13 | A |
14 | C |
15 | A |
16 | B |
17 | B |
18 | C |
19 | C |
20 | B |
21 | A |
22 | A |
23 | B |
24 | A |
25 | C |