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

MongoDB stores data in JSON structure based documents. These documents in turn contains data in form of key value pairs.

Q 2 - 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

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.

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 - Which of the following methods can be used on a cursor object?

A - cursor.next()

B - cursor.hasNext()

C - cursor.forEach()

D - All of the above

Answer : D

Explanation

All of the above methods can be used on a cursor object.

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

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.

Answer : A

Explanation

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

Q 10 - 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.

mongodb_questions_answers.htm
Advertisements