MongoDB Online Quiz


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 : D

Explanation

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

Q 2 - 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 3 - 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 4 - Consider that our posts collection contains an array field called tags that contains tags that the user enters.

{
            _id: 1,
            tags: [tutorial, fun, learning],
            post_text: This is my first post,	
            //other elements of document  	
}

What does the following command return:

db.posts.find( { 'tags.0': tutorial } )

A - All the posts whose tags array contains tutorial

B - All the posts which contains only one tag element in the tag array

C - All the posts having the first element of the tags array as tutorial

D - All the posts which contains 0 or more tags named tutorial

Answer : C

Explanation

tags.0 means that the 0th element of the tag. This is the specific matching of an element in array.

Q 5 - If the value of totalKeysExamined is 30000 and the value of totalDocsExamined is 0, which of the following option is correct?

A - The query used an index to fetch the results

B - The query returned 30000 documents after scanning the documents

C - The query returned 0 documents

D - None of the above

Answer : A

Explanation

When an index covers a query, the explain result has an IXSCAN stage that is not a descendant of a FETCH stage, and in the executionStats, the totalDocsExamined is 0.

Q 6 - 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 : 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 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 - 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.

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.

mongodb_questions_answers.htm