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

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.

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

Explanation

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

Q 4 - Consider that you are using { upsert : true } option in your update command. Which of the following parameters will be used to determine if any new documents were inserted:

A - nMatched

B - nInserted

C - nModified

D - nUpserted

Answer : D

Explanation

The nUpserted shows the number of documents that were added during the update operation.

Q 5 - You can implement a multi-document transaction in MongoDB using which of the following concept?

A - Tailable Cursor

B - Two Phase Commits

C - Compound Indexing

D - Multi Document Transaction is not supported by MongoDB

Answer : B

Explanation

Operations on a single document are always atomic with MongoDB databases; however, operations that involve multiple documents, which are often referred to as “multi-document transactions”, are not atomic.

Q 6 - What is the default size of a GridFS chunk?

A - 16 MB

B - 255 K

C - 1 MB

D - 2 MB

Answer : B

Explanation

By default GridFS limits chunk size to 255k.

Q 7 - What is the minimum sensible number of voting nodes to a replica set?

A - 2

B - 3

C - 4

D - 5

Answer : B

Explanation

The minimum number of sensible number of voting nodes is 3.

Q 8 - In a replica set, a ________ number of members ensures that the replica set is always able to select a primary.

A - Odd

B - Even

C - Depends on the application architecture

D - 2

Answer : A

Explanation

An odd number of members ensures that the replica set is always able to elect a primary. If you have an even number of members, add an arbiter to get an odd number.

Q 9 - Consider that you have the following two documents in the products collection:

{ "_id" : 1, "prices" : [ 60, 100, 200 ] }

{ "_id" : 2, "prices" : [ 20, 90, 150 ] }

What will the following query result into:
db.products.update(
   { _id: 1, prices: 100 },
   { $set: { "prices.$" : 111 } }
)

A - Updates 60 to 100

B - Updates 100 to 111

C - Updates 60,100 and 200 to 111

D - Removes the three elements of the prices array and replaces it with only a single element 111

Answer : B

Explanation

The positional $ operator identifies an element in an array to update without explicitly specifying the position of the element in the array. To project, or return, an array element from a read operation, see the $ projection operator.

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

Explanation

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

mongodb_questions_answers.htm
Advertisements