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 - What is the maximum size of a MongoDB document?

A - 2 MB

B - 16 MB

C - 12 MB

D - There is no maximum size. It depends on the RAM.

Answer : B

Explanation

The maximum BSON document size is 16 megabytes. The maximum document size helps ensure that a single document cannot use excessive amount of RAM or, during transmission, excessive amount of bandwidth.

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 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 - Consider the following posts document:

{
 	_id: 1,
	post_text: “This is my first post”,
	author: “Tom”,
	tags: [“tutorial”,”quiz”,”facebook”,”learning”,”fun”]
}

Which of the following queries will return the documents but with only the first two tags in the tags array?

A - db.posts.find({author:"Tom"},{tags:{$slice:2}})

B - db.posts.find({author:"Tom"}).limit({tags:2})

C - db.posts.find({author:"Tom"}).limit($slice:{tags:2})

D - Both a and c are valid. $slice works both with projection and limit.

Answer : A

Explanation

The $slice operator controls the number of items of an array that a query returns.

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 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 as well as acknowledged by at least 3 nodes. What should be the value of w?

A - 0

B - 1

C - 3

D - 7

Answer : C

Explanation

The value of w determines the writes are committed and acknowledged by some minimum number of nodes which in this case is 3.

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 - The oplog (operations log) is a special capped collection that keeps a rolling record of all operations that modify the data stored in your databases. All the replica set members contain a copy of the oplog in the following collection:

A - oplog.rs

B - local.oplog.rs

C - <database>..oplog.rs

D - <replicasetid>.oplog.rs

Answer : B

Explanation

All replica set members contain a copy of the oplog, in the local.oplog.rs collection, which allows them to maintain the current state of the database.

Q 10 - If you have created a compound index on (A,B, C) which of the following access pattern will not be able to utilize the index?

A - A, B, C

B - A, B

C - B, C

D - A

Answer : C

Explanation

Since the index itself starts from A, it cannot be utilized it the input query is starting with B.

mongodb_questions_answers.htm
Advertisements