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.

Q 2 - Which of the following command can be used in mongo shell to show all the databases in your MongoDB instance?

A - show dbs

B - show databases

C - show dbs -all

D - ls dbs

Answer : A

Explanation

show dbs returns the list of all the databases.

Answer : C

Explanation

When the mongo shell interprets this query, it will override the first condition $gt and consider only the $lt one. To apply both the less than and greater than condition, you will have to use the $and operator.

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 - Consider the following posts document:

{
 	_id: 1,
	post_text: This is my first post,
	author: Tom,
	tags: [tutorial,quiz,facebook,learning,fun]
}

Which of the following queries will return the documents but with only the first two tags in the tags array?

A - db.posts.find({author:"Tom"},{tags:{$slice:2}})

B - db.posts.find({author:"Tom"}).limit({tags:2})

C - db.posts.find({author:"Tom"}).limit($slice:{tags:2})

D - Both a and c are valid. $slice works both with projection and limit.

Answer : A

Explanation

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

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

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 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 - The ________ operator limits the contents of an array field from the query results to contain only the first element matching the query condition.

A - $

B - $elemMatch

C - $slice

D - An array cannot be retrieved element wise in MongoDB.

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