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.
Q 1 - Which of the following is a valid MongoDB JSON document:
B
{
"user_id"=1,
"user_name"="Joe Sanders",
"occupation"=["engineer","writer"]
}
C
{
"user_id":1;
"user_name":"Joe Sanders";
"occupation":["engineer","writer"]
}
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 - mongoimport command is used to:
A - import all the data from one database to another
B - import all the data from one collection to another
C - imports content from an Extended JSON, CSV, or TSV export created by mongoexport
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 operations on a single document will operate atomically?
Answer : C
Explanation
Both the update and $push operators will operate in an atomic way.
Q 4 - What does the following query do when performed on the posts collection?
db.posts.update({_id:1},{Title:This is post with ID 1"})
A - Updates the Title of the post
B - Updating a document is possible only with $set
C - Replaces the complete document with _id as 1 with the document specified in second parameter
Answer : C
Explanation
Updating a document without using $set replaces the entire document with whatever document is specified in second parameter.
Q 5 - If the value of totalKeysExamined is 30000 and the value of totalDocsExamined is 0, which of the following option is correct?
A - The query used an index to fetch the results
B - The query returned 30000 documents after scanning the documents
Answer : A
Explanation
When an index covers a query, the explain result has an IXSCAN stage that is not a descendant of a FETCH stage, and in the executionStats, the totalDocsExamined is 0.
Q 6 - For capped collection, cursors which do not automatically close and remain open after the client exhausts the results are called:
Answer : B
Explanation
By default, MongoDB will automatically close a cursor when the client has exhausted all results in the cursor. However, for capped collections you may use a Tailable Cursor that remains open after the client exhausts the results in the initial cursor.
Q 7 - What does the following aggregate query perform?
db.posts.aggregate( [ { $match : { likes : { $gt : 100, $lte : 200 } } }, { $group: { _id: null, count: { $sum: 1 } } } ] );
A - Calculates the number of posts with likes between 100 and 200
B - Groups the posts by number of likes (101, 102, 103�.) by adding 1 every time
C - Fetches the posts with likes between 100 and 200 and sets their _id as null
Answer : A
Explanation
The above query basically matches all the documents having likes between 100 and 200. After that, it just specifies that aggregation is not to be done with any specific column (_id:null) and increments the count every time. Thus calculating the total such posts.
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 - Which format/standard is used by MongoDB internally to store documents?
Answer : A
Explanation
MongoDB uses BSON, a binary object format similar to, but more expressive than JSON.
Q 10 - Which index is used to index the content stored in arrays?
Answer : A
Explanation
MongoDB uses multikey indexes to index the content stored in arrays. If you index a field that holds an array value, MongoDB creates separate index entries for every element of the array.