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

Explanation

Both findOne() and find() queries are very much different. The find() method returns the cursor while the findOne() returns the actual document. Hence Option b is incorrect and rest of them are correct.

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 operations on a single document will operate atomically?

A - update

B - $push

C - Both a and b

D - None of the above

Answer : C

Explanation

Both the update and $push operators will operate in an atomic way.

Answer : B

Explanation

{multi:true} should be used for this purpose. By default, MongoDB will update only the first 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 - Which of the following collections are used by MongoDB to store GridFS data?

A - fs.files and fs.chunks

B - fs.grid and fs.chunks

C - fs.parts and fs.files

D - fs.chunks and fs.parts

Answer : A

Explanation

GridFS stores files in two collections: chunks stores the binary chunks and files stores the file’s metadata.

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. What should be the value of j?

A - 0

B - 1

C - 2

D - 7

Answer : B

Explanation

To enable the disk journaling commits, j value should always be set to 1.

Q 8 - Which of the following command is used to get all the indexes on a collection?

A - db.collection.getIndexes()

B - db.collection.showIndexes()

C - db.collection.findIndexes()

D - db.showIndexes()

Answer : A

Explanation

db.collection.getIndexes() is the correct choice.

Answer : A

Explanation

In the aggregation pipeline, it is not necessary to have a $group or $project or $match before the $sort operation.

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