MongoDB Online Quiz


Advertisements

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

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 2 - 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 3 - 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.

Answer : B

Explanation

{multi:true} should be used for this purpose. By default, MongoDB will update only the first document.

Q 5 - Which option should be used with findAndModify() command to return the modified document instead of the pre-modification document?

A - findAndModify by default returns the pre-modification document

B - Set {new : true}

C - Use the POST version of findAndModify called findAndModifyPost

D - Both b and c are valid

Answer : B

Explanation

When true, returns the modified document rather than the original. The findAndModify() method ignores the new option for remove operations. The default is false.

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

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 8 - 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 9 - 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 10 - 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.

mongodb_questions_answers.htm
Advertisements