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

Q 1 - A collection and a document in MongoDB is equivalent to which of the SQL concepts respectively?

A - Table and Row

B - Table and Column

C - Column and Row

D - Database and Table

Answer : A

Explanation

The way SQL databases stores data rows in a table, MonngoDB stores documents inside collections.

Q 2 - What is the maximum size of a MongoDB document?

A - 2 MB

B - 16 MB

C - 12 MB

D - There is no maximum size. It depends on the RAM.

Answer : B

Explanation

The maximum BSON document size is 16 megabytes. The maximum document size helps ensure that a single document cannot use excessive amount of RAM or, during transmission, excessive amount of bandwidth.

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.

Q 4 - Consider that our posts collection contains an array field called tags that contains tags that the user enters.

{
            _id: 1,
            tags: [“tutorial”, “fun”, “learning”],
            post_text: “This is my first post”,	
            //other elements of document  	
}

What does the following command return:

db.posts.find( { 'tags.0': “tutorial” } )

A - All the posts whose tags array contains tutorial

B - All the posts which contains only one tag element in the tag array

C - All the posts having the first element of the tags array as tutorial

D - All the posts which contains 0 or more tags named tutorial

Answer : C

Explanation

tags.0 means that the 0th element of the tag. This is the specific matching of an element in array.

Q 5 - Which type of indexes does MongoDB support?

A - Compound Indexes

B - Multikey Indexes

C - Geospatial Indexes

D - All of the above

Answer : D

Explanation

MongoDB supports all of the above mentioned indexes.

Q 6 - What is the equivalent command in MongoDB for the following SQL query?

SELECT * FROM posts WHERE author like "%john%"

A - db.posts.find( { author: /john/ } )

B - db.posts.find( { author: {$like: /john/} } )

C - db.posts.find( { $like: {author: /john/} } )

D - db.posts.find( { author: /^john^/ } )

Answer : A

Explanation

db.posts.find( { author: /john/ } )

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 as well as acknowledged by at least 3 nodes. What should be the value of w?

A - 0

B - 1

C - 3

D - 7

Answer : C

Explanation

The value of w determines the writes are committed and acknowledged by some minimum number of nodes which in this case is 3.

Q 8 - Given the following posts document:

{
 "_id" : 1, 
 "post_text" : "This post does not matter”, 
  “tags”: [ "tutorial", "fun", "learning"],
  // rest of the document
}

What will be the output of following query:

db.posts.aggregate( [ { $unwind : "$tags" } ] )

A - Return three separate documents for three separate tags

B - Arranges the tags (wind) in ascending order

C - Arranges the tags (wind) in descending order

D - Returns one document but converts the tags array in an object

Answer : A

Explanation

Deconstructs an array field from the input documents to output a document for each element. Each output document is the input document with the value of the array field replaced by the element.

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 - Suppose that you have the following three documents in your system:

{ _id: 1, product_code: "123456", description: "mongo db tutorial" }

{ _id: 2, product_code: "345567", description: “this is mongo tutorial" }

{ _id: 3, product_code: “123431", description: "my mongo” }

If you create a text index on the description field and then apply a text search on term “mongo”, which all documents will be fetched.

A - 1 and 2

B - 2 and 3

C - 1 and 3

D - All of the above

Answer : D

Explanation

MongoDB provides text indexes to support text search of string content in documents of a collection. text indexes can include any field whose value is a string or an array of string elements.

mongodb_questions_answers.htm
Advertisements