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.

Questions and Answers

MongoDB Mock Test IV

Answer : B

Explanation

The query in option 2, first of all groups the records by _id as author. This will group all the posts with same author and calculate the sum. Now that we have the sum with us, we are filtering on this count being greater than 1 in the next $match statement.

Q 2 - Which of the following aggregate commands in MongoDB uses a pipeline approach with the goals of improving the aggregation performance?

A - aggregate

B - mapReduce

C - group

D - All of the above

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 3 - Which of the following aggregation commands in MongoDB does not support sharded collections?

A - aggregate

B - mapReduce

C - group

D - All of the above

Answer : C

Explanation

The group command in MongoDB groups documents in a collection by the specified key and performs simple aggregation functions, such as computing counts and sums. It is the most basic one and does not support such sharding concepts.s

Q 4 - What is a replica set node which does not maintain its own data but exists only for voting purpose called?

A - Secondary

B - Arbiter

C - Delayed

D - Hidden

Answer : B

Explanation

We may add an extra mongod instance to a replica set as an arbiter. Arbiters do not maintain a data set. Arbiters only exist to vote in elections. If your replica set has an even number of members, add an arbiter to obtain a majority of votes in an election for primary. Arbiters do not require dedicated hardware

Q 5 - In a replica set, a ________ number of members ensures that the replica set is always able to select a primary.

A - Odd

B - Even

C - Depends on the application architecture

D - 2

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 6 - Which of the tags in a replica set configuration specify the operations to be read from the node with the least network latency?

A - primaryPreferred

B - secondaryPreferred

C - nearest

D - netLatency

Answer : C

Explanation

Operations read from member of the replica set with the least network latency, irrespective of the member’s type.

Q 7 - The oplog (operations log) is a special capped collection that keeps a rolling record of all operations that modify the data stored in your databases. All the replica set members contain a copy of the oplog in the following collection:

A - oplog.rs

B - local.oplog.rs

C - <database>..oplog.rs

D - <replicasetid>.oplog.rs

Answer : B

Explanation

All replica set members contain a copy of the oplog, in the local.oplog.rs collection, which allows them to maintain the current state of the database.

Q 8 - In a sharded replica set environment, w defines the level and kind of write concern. Which of the following values of w specifies to return success only after a majority of voting members have acknowledged?

A - n

B - majority

C - m

D - major

Answer : B

Explanation

For replica sets, if you specify the special majority value to w option, write operations will only return successfully after a majority of the voting members of the replica set have acknowledged the write operation.

Q 9 - Which of the following is the correct syntax for starting a new mongod process and specifying its replica set name as rs0:

A - mongod --replSet "rs0"

B - mongod --repl "rs0"

C - mongod "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.

Answer : A

Explanation

In the aggregation pipeline, it is not necessary to have a $group or $project or $match before the $sort operation.

Q 12 - Which format/standard is used by MongoDB internally to store documents?

A - BSON

B - JSON

C - JSON - Extended

D - B+ Trees

Answer : A

Explanation

MongoDB uses BSON, a binary object format similar to, but more expressive than JSON.

Q 13 - Which of the following operators can reverse the effects of a double unwind operation?

A - $push

B - $wind

C - $wind.$wind

D - Can’t be reversed.

Answer : A

Explanation

An unwind operation unwinds on an array field and creates separate documents. If you unwind it again same thing happens again. So if you had one document which had two arrays, the first array had 2 values and second array has 3 values. Unwinding this document two times will give 6 document. Now to combine them back, you can use the $push operator.

Q 14 - We can insert multiple documents in bulk using which of the following operations:

A - initializeUnorderedBulkOp

B - initializeBulkOp

C - initializeBulk

D - initializeUnorderedBulk

Answer : A

Explanation

The initializeUnorderedBulkOp operation returns an unordered operations builder which maintains a list of operations to perform. Unordered operations means that MongoDB can execute in parallel as well as in nondeterministic order.

Q 15 - 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 } }
)

A - Updates 60 to 100

B - Updates 100 to 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 16 - The _______ operator can be used to identify an element in the array to be updated without explicitly specifying the position of the element.

A - $

B - $elemMatch

C - $slice

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.

Q 17 - The ________ operator limits the contents of an array field from the query results to contain only the first element matching the query condition.

A - $

B - $elemMatch

C - $slice

D - An array cannot be retrieved element wise in MongoDB.

Answer : B

Explanation

The $elemMatch operator limits the contents of an array field from the query results to contain only the first element matching the $elemMatch condition.

Q 18 - Consider the following document from the products collection:

{
 _id: 1,
 product_code: "345678",
 variations: [
              { size: "L", price: 1000 },
              { size: "M", price: 800 }
           ]
}

What does the following query using $elemMatch return?

db.products.find( { product_code: "345678" },
                 { variations: { $elemMatch: { size: “L” } } } )

A - Returns the complete document since MongoDB does not support partial array retrieval

B - Returns the document but with only one element in the variations array (corresponding to size L)

C - Returns the complete document but retrieves only the size field from the array

D - Returns the complete document but retrieves only the size field from the array and also with only one element in the variations array (corresponding to size L)

Answer : B

Explanation

The $elemMatch operator limits the contents of an <array> field from the query results to contain only the first element matching the $elemMatch condition.

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.

Q 20 - Which of the following operator can be used to control the number of items of an array that a query returns?

A - $

B - $elemMatch

C - $slice

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.

Q 21 - When should we consider representing a one-to-many relationship in an embedded collection instead of separate collection?

A - When the many is very large

B - When the many is not very large

C - Never

D - Always

Answer : B

Explanation

If the many is very large, then we should create separate collection, else the document size would go on increasing.

Q 22 - Which index is used to index the content stored in arrays?

A - Multikey Index

B - Compound Index

C - Text Index

D - Sparse Index

Answer : A

Explanation

MongoDB uses multikey indexes to index the content stored in arrays. If you index a field that holds an array value, MongoDB creates separate index entries for every element of the array.

Q 23 - Suppose that you have the following three documents in your system:

{ _id: 1, product_code: "123456", description: "mongo db tutorial" }

{ _id: 2, product_code: "345567", description: “this is mongo tutorial" }

{ _id: 3, product_code: “123431", description: "my mongo” }

If you create a text index on the description field and then apply a text search on term “mongo”, which all documents will be fetched.

A - 1 and 2

B - 2 and 3

C - 1 and 3

D - All of the above

Answer : D

Explanation

MongoDB provides text indexes to support text search of string content in documents of a collection. text indexes can include any field whose value is a string or an array of string elements.

Q 24 - If you have created a compound index on (A,B, C) which of the following access pattern will not be able to utilize the index?

A - A, B, C

B - A, B

C - B, C

D - A

Answer : C

Explanation

Since the index itself starts from A, it cannot be utilized it the input query is starting with B.

Answer : C

Explanation

If you need to rebuild indexes for a collection you can use the db.collection.reIndex() method to rebuild all indexes on a collection in a single operation. This operation drops all indexes, including the _id index, and then rebuilds all indexes.

Answer Sheet

Question Number Answer Key
1 B
2 A
3 C
4 B
5 A
6 C
7 B
8 B
9 A
10 A
11 C
12 B
13 A
14 A
15 B
16 A
17 B
18 B
19 A
20 C
21 B
22 A
23 D
24 C
25 C
mongodb_questions_answers.htm
Advertisements