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 - Which of the following command can be used to check the size of a collection named posts?

A - db.posts.stats()

B - db.posts.findStats()

C - db.posts.find({stats:1})

D - db.stats({ collection : posts })

Answer : A

Explanation

To view the statistics for a collection, including the data size, use the db.collection.stats() method from the mongo shell.

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 - Which of the following operator can be used to limit the number of documents in an array field of a document after an update is performed?

A - $push along with $each, $sort and $slice

B - $removeFromSet

C - $arrayLimit

D - None of the above

Answer : A

Explanation

You can iterate over all the array elements using $each, slice them using $slice and then push them back to the document using $push.

Q 6 - Update If Correct is an approach for which of the following concepts in MongoDB:

A - Concurrency Control

B - Transaction Management

C - Atomicity

D - Performance Management

Answer : A

Explanation

The Update if Current pattern is an approach to concurrency control when multiple applications have access to the data.

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.

Answer : A

Explanation

MongoDB cannot create a unique index on the specified index field(s) if the collection already contains data that would violate the unique constraint for the index. The syntax for the same is db.collection.createIndex( { a: 1 }, { unique: true } )

Q 9 - Which of the following is the correct syntax for starting a new mongod process and specifying its replica set name as rs0:

A - mongod --replSet "rs0"

B - mongod --repl "rs0"

C - mongod "rs0"

D - First execute this: mongod --replSet. And then execute this: rs.add()

Answer : A

Explanation

Replica set can be set/stated using the –replSet command and specifying the replica name with it.

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