MongoDB Online Quiz


Advertisements


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

Q 1 - A collection and a document in MongoDB is equivalent to which of the SQL concepts respectively?

A - Table and Row

B - Table and Column

C - Column and Row

D - Database and Table

Answer : A

Explanation

The way SQL databases stores data rows in a table, MonngoDB stores documents inside collections.

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

Answer : B

Explanation

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

Answer : D

Explanation

There is no system collection to store database preferences.

Q 7 - The following aggregation option is used to specify the specific fields that needs to be passed to the next stage of the aggregation pipeline:

A - $match

B - $project

C - $group

D - $aggregate

Answer : B

Explanation

The $project operator passes along the documents with only the specified fields to the next stage in the pipeline. The specified fields can be existing fields from the input documents or newly computed fields.

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