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

Explanation

A blank document is valid in MongoDB. However, rest of the three documents have some or the other problem. Option b has “=”, Option c has “;” and Option d has an incorrect array format. It should be a sub-document instead.

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

MongoDB does not support things like ACID Transactions or atomicity across collections or relationships like SQL.

Q 4 - Which of the following commands removes a single document that matches the condition that Author is Joe?

A - db.posts.removeOne( { Author : "Joe" }, 1 )

B - db.posts.remove( { Author : "Joe" }, 1 )

C - db.posts.remove( { Author : "Joe" }, {justOne: true} )

D - Both b and c

Answer : D

Explanation

The third parameter to the remove function is justOne. You can either simply say 1 or write justOne as true.

Q 5 - Which language is MongoDB written in?

A - C++

B - Java

C - Python

D - MongoC

Answer : A

Explanation

MongoDB is written in C++.

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 - 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 - Given a collection posts as shown below having a document array comments, which of the following command will create an index on the comment author descending?

{
		“_id”:1,
		“post_text”:”This is a sample post”,
		“author”:”Tom”,
		“comments”:[
			{
				“author”:”Joe”,
				“comment_text”:”This is comment 1”
			},
			{
				“author”:”Leo”,
				“comment_text”:”This is comment 2”
			}
		]	
}

A - db.posts.createIndex({“comments.$.author":-1});

B - db.posts.createIndex({“comments.author":-1});

C - db.posts.createIndex({“comments.author":1});

D - db.posts.createIndex({“comments.$.author": {“$desc”:1}});

Answer : B

Explanation

We can access the document fields within an array using dot notation. And for indicating the index sorting, we just have to mention 1 or -1.

Answer : A

Explanation

The $slice operation selects the document collection identified by a field named field that holds value and returns the number of elements specified by the value of count from the array stored in the array field.

mongodb_questions_answers.htm
Advertisements