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

Explanation

A blank document is valid in MongoDB. However, rest of the three documents have some or the other problem. Option b has “=”, Option c has “;” and Option d has an incorrect array format. It should be a sub-document instead.

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.

Answer : A

Explanation

The efficiency of a MongoDB database depends on how well the database is designed depending on the application usage. The schema should be designed based on how the data access patterns are.

Q 4 - Consider that the posts collection contains an array called ratings which contains ratings given to the post by various users in the following format:

{
         _id: 1,
         post_text: “This is my first post”,
         ratings: [5, 4, 2, 5],
         //other elements of document 			
}

Which of the following query will return all the documents where the ratings array contains elements that in some combination satisfy the query conditions?

A - db.inventory.find( { ratings: { $elemMatch: { $gt: 3, $lt: 6 } } } )

B - db.inventory.find( { ratings: { ratings: { $gt: 5, $lt: 9 } } } )

C - db.inventory.find( { ratings: { ratings.$: { $gt: 5, $lt: 9 } } } )

D - db.inventory.find( { ratings: { $elemMatch: { $gte: 3, $lte: 6 } } } )

Answer : B

Explanation

This query will check if the array elements match the given condition in some or the other way or combination.

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

Explanation

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: http://docs.mongodb.org/manual/reference/bson-types/

Q 7 - In a sharded replicas set environment with multiple mongos servers, which of the following would decide the mongos failover?

A - mongo shell

B - mongod

C - individual language drivers

D - mongos

Answer : C

Explanation

Since the mongos are itself failing in this case, this logic has to be built on the drivers side.

Q 8 - Given the following posts document:

{
 "_id" : 1, 
 "post_text" : "This post does not matter”, 
  “tags”: [ "tutorial", "fun", "learning"],
  // rest of the document
}

What will be the output of following query:

db.posts.aggregate( [ { $unwind : "$tags" } ] )

A - Return three separate documents for three separate tags

B - Arranges the tags (wind) in ascending order

C - Arranges the tags (wind) in descending order

D - Returns one document but converts the tags array in an object

Answer : A

Explanation

Deconstructs an array field from the input documents to output a document for each element. Each output document is the input document with the value of the array field replaced by the element.

Q 9 - Which of the following operators can reverse the effects of a double unwind operation?

A - $push

B - $wind

C - $wind.$wind

D - Can’t be reversed.

Answer : A

Explanation

An unwind operation unwinds on an array field and creates separate documents. If you unwind it again same thing happens again. So if you had one document which had two arrays, the first array had 2 values and second array has 3 values. Unwinding this document two times will give 6 document. Now to combine them back, you can use the $push operator.

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