MongoDB Mock Test


Advertisements

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.

Questions and Answers

MongoDB Mock Test III

Q 1 - Update If Correct is an approach for which of the following concepts in MongoDB:

A - Concurrency Control

B - Transaction Management

C - Atomicity

D - Performance Management

Answer : A

Explanation

The Update if Current pattern is an approach to concurrency control when multiple applications have access to the data.

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.

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/} } )

C - db.posts.find( { $like: {author: /john/} } )

D - db.posts.find( { author: /^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:

A - Capped Cursors

B - Tailable Cursors

C - Open Cursors

D - Indexing Cursors

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.

Q 6 - What is the default size of a GridFS chunk?

A - 16 MB

B - 255 K

C - 1 MB

D - 2 MB

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?

A - fs.files and fs.chunks

B - fs.grid and fs.chunks

C - fs.parts and fs.files

D - fs.chunks and fs.parts

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

C - String, Null, Number and Object

D - Null, Number, Object and String

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/

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.

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?

A - Manual References

B - DBRefs

C - Both a and b

D - There is no concept of relations in 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.

A - $group

B - $match

C - $aggregate

D - $sum

Answer : B

Explanation

$match filters the documents to pass only the documents that match the specified condition(s) to the next pipeline stage.

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

D - Sum of likes on all the posts by all the authors

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.

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?

A - 2

B - 3

C - 4

D - 5

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?

A - 0

B - 1

C - 2

D - 7

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?

A - 0

B - 1

C - 3

D - 7

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?

A - mongo shell

B - mongod

C - individual language drivers

D - mongos

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:

A - $match

B - $project

C - $group

D - $aggregate

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()

C - db.collection.findIndexes()

D - db.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.

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?

A - WHERE

B - HAVING

C - Both WHERE and HAVING

D - GROUP BY

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
mongodb_questions_answers.htm
Advertisements