MongoDB - Java

MongoDB - PHP

MongoDB - Advanced

MongoDB - Useful Resources

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

Explanation

MongoDB stores data in JSON structure based documents. These documents in turn contains data in form of key value pairs.

Answer : C

Explanation

The mongoimport tool imports content from an Extended JSON, CSV, or TSV export created by mongoexport, or potentially, another third-party export tool.

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 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 - Which are the ONLY ways to project portions of an array?

A - $elemMatch

B - $slice

C - $

D - All of the above

Answer : D

Explanation

$elemMatch, $slice, and $ are the only way to project portions of an array. For e.g. you cannot use {tags.0:1} for projection.

Q 6 - What is the default size of a GridFS chunk?

A - 16 MB

B - 255 K

C - 1 MB

D - 2 MB

Answer : B

Explanation

By default GridFS limits chunk size to 255k.

Q 7 - What does the output x of the following MongoDB aggregation query result into:

db.posts.aggregate( [ { $group: { _id: "$author", x: { $sum: $likes } } } ] )

A - Average of likes on all the posts of an author, grouped by author

B - Number of posts by an author

C - Sum of likes on all the posts by an author, grouped by author

D - Sum of likes on all the posts by all the authors

Answer : C

Explanation

The above query first does a grouping on author field and then calculates the number of likes on all the posts that were grouped together.

Q 8 - Which of the following SQL terminology is same as $match in MongoDB?

A - WHERE

B - HAVING

C - Both WHERE and HAVING

D - GROUP BY

Answer : C

Explanation

In MongoDB, we use $match as the aggregation operator corresponding to WHERE and HAVING condition in MongoDB.

Q 9 - Which of the tags in a replica set configuration specify the operations to be read from the node with the least network latency?

A - primaryPreferred

B - secondaryPreferred

C - nearest

D - netLatency

Answer : C

Explanation

Operations read from member of the replica set with the least network latency, irrespective of the members type.

Q 10 - Which of the following operator can be used to control the number of items of an array that a query returns?

A - $

B - $elemMatch

C - $slice

D - MongoDB does not support partial retrieval of items from an array

Answer : C

Explanation

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

mongodb_questions_answers.htm
Advertisements