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

Explanation

There is no direct way of changing the sharded key unless you dump the entire data, drop the sharded key and then re-import everything. Other all options are false. Sharding is enabled at collection level, it does not create any index by default and finally sharding environment supports regular sorting.

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 - What does the following query do when performed on the posts collection?

db.posts.update({_id:1},{Title:This is post with ID 1"})

A - Updates the Title of the post

B - Updating a document is possible only with $set

C - Replaces the complete document with _id as 1 with the document specified in second parameter

D - Syntax error

Answer : C

Explanation

Updating a document without using $set replaces the entire document with whatever document is specified in second parameter.

Answer : B

Explanation

explain.executionStats.totalKeysExamined indicates the number of index entries scanned.

Q 6 - Which of the following collections are used by MongoDB to store GridFS data?

A - fs.files and fs.chunks

B - fs.grid and fs.chunks

C - fs.parts and fs.files

D - fs.chunks and fs.parts

Answer : A

Explanation

GridFS stores files in two collections: chunks stores the binary chunks and files stores the file’s metadata.

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 - 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 - Consider the following document from the products collection:

{
 _id: 1,
 product_code: "345678",
 variations: [
              { size: "L", price: 1000 },
              { size: "M", price: 800 }
           ]
}

What does the following query using $elemMatch return?

db.products.find( { product_code: "345678" },
                 { variations: { $elemMatch: { size: “L” } } } )

A - Returns the complete document since MongoDB does not support partial array retrieval

B - Returns the document but with only one element in the variations array (corresponding to size L)

C - Returns the complete document but retrieves only the size field from the array

D - Returns the complete document but retrieves only the size field from the array and also with only one element in the variations array (corresponding to size L)

Answer : B

Explanation

The $elemMatch operator limits the contents of an <array> field from the query results to contain only the first element matching the $elemMatch condition.

mongodb_questions_answers.htm
Advertisements