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

Answer : C

Explanation

The skip and limit functions are applies linearly and hence it will first skip documents 1-5, and then return documents 6-10.

Q 2 - What is the maximum size of Index Key Limit and Number of Indexes per collection?

A - 64 bytes and 1024 indexes

B - 12 mega bytes and 64 indexes

C - 1024 bytes and 64 indexes

D - 1024 bytes and unlimited indexes

Answer : C

Explanation

The total size of an index entry, which can include structural overhead depending on the BSON type, must be less than 1024 bytes. A single collection can have no more than 64 indexes.

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.

Answer : A

Explanation

When you specify upsert: true for an update operation and no matching documents are found, MongoDB creates a new document.

Q 5 - Which of the following methods can be used on a cursor object?

A - cursor.next()

B - cursor.hasNext()

C - cursor.forEach()

D - All of the above

Answer : D

Explanation

All of the above methods can be used on a cursor object.

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 - Which of the following command inside aggregate command is used in MongoDB aggregation to filter the documents to pass only the documents that match the specified condition(s) to the next pipeline stage.

A - $group

B - $match

C - $aggregate

D - $sum

Answer : B

Explanation

$match filters the documents to pass only the documents that match the specified condition(s) to the next pipeline stage.

Answer : B

Explanation

The query in option 2, first of all groups the records by _id as author. This will group all the posts with same author and calculate the sum. Now that we have the sum with us, we are filtering on this count being greater than 1 in the next $match statement.

Q 9 - Consider that you have the following two documents in the products collection:

{ "_id" : 1, "prices" : [ 60, 100, 200 ] }

{ "_id" : 2, "prices" : [ 20, 90, 150 ] }

What will the following query result into:
db.products.update(
   { _id: 1, prices: 100 },
   { $set: { "prices.$" : 111 } }
)

A - Updates 60 to 100

B - Updates 100 to 111

C - Updates 60,100 and 200 to 111

D - Removes the three elements of the prices array and replaces it with only a single element 111

Answer : B

Explanation

The positional $ operator identifies an element in an array to update without explicitly specifying the position of the element in the array. To project, or return, an array element from a read operation, see the $ projection operator.

Q 10 - When should we consider representing a one-to-many relationship in an embedded collection instead of separate collection?

A - When the many is very large

B - When the many is not very large

C - Never

D - Always

Answer : B

Explanation

If the many is very large, then we should create separate collection, else the document size would go on increasing.


mongodb_questions_answers.htm

Advertisements