- MongoDB Tutorial
- MongoDB - Home
- MongoDB - Overview
- MongoDB - Advantages
- MongoDB - Environment
- MongoDB - Data Modeling
- MongoDB - Create Database
- MongoDB - Drop Database
- MongoDB - Create Collection
- MongoDB - Drop Collection
- MongoDB - Data Types
- MongoDB - Insert Document
- MongoDB - Query Document
- MongoDB - Update Document
- MongoDB - Delete Document
- MongoDB - Projection
- MongoDB - Limiting Records
- MongoDB - Sorting Records
- MongoDB - Indexing
- MongoDB - Aggregation
- MongoDB - Replication
- MongoDB - Sharding
- MongoDB - Create Backup
- MongoDB - Deployment
- MongoDB - Java
- MongoDB - PHP
- Advanced MongoDB
- MongoDB - Relationships
- MongoDB - Database References
- MongoDB - Covered Queries
- MongoDB - Analyzing Queries
- MongoDB - Atomic Operations
- MongoDB - Advanced Indexing
- MongoDB - Indexing Limitations
- MongoDB - ObjectId
- MongoDB - Map Reduce
- MongoDB - Text Search
- MongoDB - Regular Expression
- Working with Rockmongo
- MongoDB - GridFS
- MongoDB - Capped Collections
- Auto-Increment Sequence
- MongoDB Useful Resources
- MongoDB - Questions and Answers
- MongoDB - Quick Guide
- MongoDB - Useful Resources
- MongoDB - Discussion
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 - A collection and a document in MongoDB is equivalent to which of the SQL concepts respectively?
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?
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.
Q 3 - What does the following MongoDB command return?
db.posts.find( { likes : { $gt : 100 }, likes : { $lt : 200 } } );
A - Posts with likes greater than 100 but less than 200
B - Posts with likes greater than or equal to 100 but less than or equal to 200
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?
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/} } )
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?
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 } } )
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.
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.
To Continue Learning Please Login
Login with Google