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


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


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

Which of the following commands will find all the posts that have been tagged as tutorial.

A - db.posts.find( { tags : "tutorial" } );

B - db.posts.find( { tags : ["tutorial"] } );

C - db.posts.find( { $array : {tags: "tutorial"} } );

D - db.posts.findInArray( { tags : "tutorial" } );

Answer : A


Searching an array is no different than searching a normal field. Hence the first option.

Answer : A


When you specify upsert: true for an update operation and no matching documents are found, MongoDB creates a new 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


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 - Which is the correct order (lowest to highest) in which MongoDB compares the BSON types?

A - Null, Number, String and Object

B - Number, Null, String and Object

C - String, Null, Number and Object

D - Null, Number, Object and String

Answer : A


This is the defined order in which the bson types are compared. There are various other fields as per the BSON specification which can be found here:

Q 7 - In a sharded replica set environment, the w Option provides ability for write concern and j Option provides ability for the data to be written on disk journal. Consider that we have a seven member replica set and we want to assure that the writes are committed to journal. What should be the value of j?

A - 0

B - 1

C - 2

D - 7

Answer : B


To enable the disk journaling commits, j value should always be set to 1.

Q 8 - Which of the following SQL terminology is same as $match in MongoDB?





Answer : C


In MongoDB, we use $match as the aggregation operator corresponding to WHERE and HAVING condition in MongoDB.

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


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


The positional $ operator identifies an element in an array to update without explicitly specifying the position of the element in the array.