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 I

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 - A collection and a document in MongoDB is equivalent to which of the SQL concepts respectively?

A - Table and Row

B - Table and Column

C - Column and Row

D - Database and Table

Answer : A

Explanation

The way SQL databases stores data rows in a table, MonngoDB stores documents inside collections.

Answer : D

Explanation

MongoDB provides specific supports for functionalities related to 2d and 3d geospatial problems.

Answer : A

Explanation

A blank document is valid in MongoDB. However, rest of the three documents have some or the other problem. Option b has “=”, Option c has “;” and Option d has an incorrect array format. It should be a sub-document instead.

Answer : B

Explanation

The core components in the MongoDB package are: mongod, the core database process; mongos the controller and query router for sharded clusters; and mongo the interactive MongoDB Shell.

Q 6 - Consider a collection posts which has fields: _id, post_text, post_author, post_timestamp, post_tags etc. Which of the following query retrieves ONLY the key named post_text from the first document retrieved?

A - db.posts.find({},{_id:0, post_text:1})

B - db.posts.findOne({post_text:1})

C - db.posts.finOne({},{post_text:1})

D - db.posts.finOne({},{_id:0, post_text:1})

Answer : D

Explanation

By default, MongoDB returns the _id field with each document. So in case you want ONLY the post_text field, you will have to exclude the _id field explicitly. Also, since we have to retrieve only the first document we have to use findOne and not find.

Answer : B

Explanation

Both findOne() and find() queries are very much different. The find() method returns the cursor while the findOne() returns the actual document. Hence Option b is incorrect and rest of them are correct.

Answer : C

Explanation

The skip and limit functions are applies linearly and hence it will first skip documents 1-5, and then return documents 6-10.

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 10 - The MongoDB explain() method does not support which of the following verbosity mode:

A - queryPlanner

B - executionStats

C - allPlansExecution

D - customExecutionStats

Answer : D

Explanation

The possible modes of explain() are: "queryPlanner", "executionStats", and "allPlansExecution".

Q 11 - Which is the default mode in which the explain() command runs?

A - queryPlanner

B - executionStats

C - allPlansExecution

D - customExecutionStats

Answer : A

Explanation

Default mode is "queryPlanner".

Q 12 - Within how much time does MongDB writes are written to the journal?

A - 60 s

B - 100 ms

C - 1 s

D - 100 s

Answer : B

Explanation

Writes are physically written to the journal within 100 milliseconds, by default.

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 14 - What is the maximum size of a MongoDB document?

A - 2 MB

B - 16 MB

C - 12 MB

D - There is no maximum size. It depends on the RAM.

Answer : B

Explanation

The maximum BSON document size is 16 megabytes. The maximum document size helps ensure that a single document cannot use excessive amount of RAM or, during transmission, excessive amount of bandwidth.

Q 15 - What is the maximum size of Index Key Limit and Number of Indexes per collection?

A - 64 bytes and 1024 indexes

B - 12 mega bytes and 64 indexes

C - 1024 bytes and 64 indexes

D - 1024 bytes and unlimited indexes

Answer : C

Explanation

The total size of an index entry, which can include structural overhead depending on the BSON type, must be less than 1024 bytes. A single collection can have no more than 64 indexes.

Q 16 - What is the output of the following program?

A - 60 s

B - 100 ms

C - 1 s

D - 100 s

Answer : A

Explanation

In the default configuration, MongoDB writes data to the main data files on disk every 60 seconds.

Answer : A

Explanation

$type is used for all the operations involving checking the type of a field in MongoDB. 10 represents the BSON value for null.

Answer : C

Explanation

The mongoimport tool imports content from an Extended JSON, CSV, or TSV export created by mongoexport, or potentially, another third-party export tool.

Q 19 - Which of the following command can be used in mongo shell to show all the databases in your MongoDB instance?

A - show dbs

B - show databases

C - show dbs -all

D - ls dbs

Answer : A

Explanation

show dbs returns the list of all the databases.

Q 20 - Which of the following replica sets vote in the election of a primary replica set?

A - Secondary

B - Hidden

C - Delayed

D - All of the above

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 21 - Which of the following command can be used to check the size of a collection named posts?

A - db.posts.stats()

B - db.posts.findStats()

C - db.posts.find({stats:1})

D - db.stats({ collection : 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 22 - Which of the following commands can cause the database to be locked?

A - Issuing a query

B - Inserting data

C - Map-reduce

D - All of the above

Answer : D

Explanation

All the above commands wither result in a read lock or a write lock or both.

Q 23 - By default, the MongoDB cursor in mongo shell is configured to return how many documents? To get the next set of documents, which command is used?

A - 20, it

B - 200, more

C - 50, it

D - No limit, none

Answer : A

Explanation

In the mongo shell, if the returned cursor is not assigned to a variable using the var keyword, then the cursor is automatically iterated up to 20 times [1] to print up to the first 20 documents in the results. To get the next set of results, you should use it command which will iterate over the next set of results.

Answer : D

Explanation

Since 100 and 200 are both inclusive, we need $gte (greater than and equal) and $lte (less than and equal).

Answer : A

Explanation

The $gt, $lt and related operators can be applied for string manipulations too. They work in the same manner as they would work on numeric values.

Answer Sheet

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