MongoDB Mock Test

This section presents you various set of Mock Tests related to MongoDB Framework.  You can download these sample mock tests at your local machine and solve offline at your convenience. Every mock test is supplied with a mock test key to let you verify the final score and grade yourself.
Q 1 - What kind of database MongoDB is?
A - Graph Oriented
B - Document Oriented 
C - Key Value Pair 
D - Column Based
MongoDB stores data in JSON structure based documents. These documents in turn contains data in form of key value pairs.
Q 2 - 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 
The way SQL databases stores data rows in a table, MonngoDB stores documents inside collections.
Q 3 - Which of the following is correct about MongoDB?
A - MongoDB uses JSON format to represent documents
B - MongoDB supports collection joins 
C - MongoDB supports some of the SQL functions 
D - MongoDB supports geospatial indexes
MongoDB provides specific supports for functionalities related to 2d and 3d geospatial problems.
Q 4 - Which of the following is a valid MongoDB JSON document:
A

{}
B

{
	"user_id"=1,
	"user_name"="Joe Sanders",
	"occupation"=["engineer","writer"]
}
C

{
	"user_id":1;
	"user_name":"Joe Sanders";
	"occupation":["engineer","writer"]
} 
D

{
	"user_id":1,
	"user_name":"Joe Sanders",
	"occupation":[
		"occupation1":"engineer",
		"occupation2":"writer"
	]
}
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 5 - Which of the following is correct explanation of MongoDB processes?
A - mongod.exe is the shell process and mongo.exe is the actual database process
B - mongo.exe is the shell process and mongod.exe is the actual database process
C - mongos.exe is the MongoDB server process needed to run database 
D - mongodump.exe can be used to import database backup dump 
The core components in the MongoDB package are: mongod, the core database process; mongos the controller and query router for sharded clusters; and mongo the interactive MongoDB Shell.
Q 6 - Consider a collection posts which has fields: _id, post_text, post_author, post_timestamp, post_tags etc. Which of the following query retrieves ONLY the key named post_text from the first document retrieved?
A - db.posts.find({},{_id:0, post_text:1})
B - db.posts.findOne({post_text:1})
C - db.posts.finOne({},{post_text:1})
D - db.posts.finOne({},{_id:0, post_text:1})
By default, MongoDB returns the _id field with each document. So in case you want ONLY the post_text field, you will have to exclude the _id field explicitly. Also, since we have to retrieve only the first document we have to use findOne and not find.
Q 7 - Which of the following is incorrect statement about find and findOne operations in MongoDB?
A - find() returns all the documents in a collection while findOne() retrieves only the first one. 
B - find() and findOne() returns cursors to the collection documents
C - findOne() returns the actual first document retrieved from a collection
D - find.limit(1) is not the same query as findOne()
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.
Q 8 - In a collection that contains 100 post documents, what does the following command do?
db.posts.find().skip(5).limit(5)
A - Skip and limit nullify each other. Hence returning the first five documents.
B - Skips the first five documents and returns the sixth document five times
C - Skips the first five documents and returns the next five 
D - Limits the first five documents and then return them in reverse order
The skip and limit functions are applies linearly and hence it will first skip documents 1-5, and then return documents 6-10.
Q 9 - Which of the following MongoDB query is equivalent to the following SQL query:
UPDATE users SET status = "C" WHERE age > 25
A

db.users.update(
   { age: { $gt: 25 } },
   { status: "C" })
B

db.users.update(
 { age: { $gt: 25 } },
 { $set: { status: "C" } })
C

db.users.update(
 { age: { $gt: 25 } },
 { $set: { status: "C" } },
 { multi: true })
D

db.users.update(
 { age: { $gt: 25 } },
 { status: "C" },
 { multi: true })
$set is used to set the value of a particular field in a document. The syntax of set is $set:{column_name : column_value}. Also, {multi:true} is needed to update all the documents. Otherwise only the first found document is updated.
Q 10 - The MongoDB explain() method does not support which of the following verbosity mode:
A - queryPlanner
B - executionStats
C - allPlansExecution
D - customExecutionStats
The possible modes of explain() are: "queryPlanner", "executionStats", and "allPlansExecution".
Q 11 - Which is the default mode in which the explain() command runs?
A - queryPlanner
B - executionStats
C - allPlansExecution
D - customExecutionStats
Default mode is "queryPlanner".
Q 12 - Within how much time does MongDB writes are written to the journal?
A - 60 s
B - 100 ms
C - 1 s
D - 100 s
Writes are physically written to the journal within 100 milliseconds, by default.
Q 13 - Which of the following is true about sharding?
A - Sharding is enabled at the database level
B - Creating a sharded key automatically creates an index on the collection using that key
C - We cannot change a shard key directly/automatically once it is set up
D - A sharded environment does not support sorting functionality since the documents lie on various mongod instances
There is no direct way of changing the sharded key unless you dump the entire data, drop the sharded key and then re-import everything. Other all options are false. Sharding is enabled at collection level, it does not create any index by default and finally sharding environment supports regular sorting.
Q 14 - 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.
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 15 - What is the maximum size of Index Key Limit and Number of Indexes per collection?
A - 64 bytes and 1024 indexes
B - 12 mega bytes and 64 indexes
C - 1024 bytes and 64 indexes
D - 1024 bytes and unlimited indexes
The total size of an index entry, which can include structural overhead depending on the BSON type, must be less than 1024 bytes. A single collection can have no more than 64 indexes.
Q 16 - What is the output of the following program?
A - 60 s
B - 100 ms
C - 1 s 
D - 100 s
In the default configuration, MongoDB writes data to the main data files on disk every 60 seconds.
Q 17 - Which of the following commands finds all the documents in the posts collection with post timestamp field as null?
A - db.posts.find( { post_timestamp : { $type: 10 } } )
B - db.posts.find( { post_timestamp: { $type: null } } )
C - db.posts.find( { post_timestamp: { $fieldtype: 10 } } )
D - db.posts.find( { post_timestamp: { $fieldtype: null } } )
$type is used for all the operations involving checking the type of a field in MongoDB. 10 represents the BSON value for null.
Q 18 - 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
D - import all the MongoDB data from one format to another
The mongoimport tool imports content from an Extended JSON, CSV, or TSV export created by mongoexport, or potentially, another third-party export tool.
Q 19 - 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
show dbs returns the list of all the databases.
Q 20 - Which of the following replica sets vote in the election of a primary replica set?
A - Secondary 
B - Hidden 
C - Delayed
D - All of the above
All members of a replica set, unless the value of votes is equal to 0, vote in elections. This includes all delayed, hidden and secondary-only members.
Q 21 - Which of the following command can be used to check the size of a collection named posts?
A - db.posts.stats()
B - db.posts.findStats()
C - db.posts.find({stats:1})
D - db.stats({ collection : posts })
To view the statistics for a collection, including the data size, use the db.collection.stats() method from the mongo shell.
Q 22 - Which of the following commands can cause the database to be locked?
A - Issuing a query 
B - Inserting data 
C - Map-reduce  
D - All of the above
All the above commands wither result in a read lock or a write lock or both.
Q 23 - By default, the MongoDB cursor in mongo shell is configured to return how many documents? To get the next set of documents, which command is used?
A - 20, it
B - 200, more
C - 50, it
D - No limit, none
In the mongo shell, if the returned cursor is not assigned to a variable using the var keyword, then the cursor is automatically iterated up to 20 times [1] to print up to the first 20 documents in the results. To get the next set of results, you should use it command which will iterate over the next set of results.
Q 24 - Which of the following commands will return all the posts with number of likes greater than 100 and less than 200, both inclusive?
A - db.posts.find({ likes : { $gt : 100, $lt : 200 } } );
B - db.posts.find({ likes : { $gte : 100, $lt : 200 } } );
C - db.posts.find({ likes : { $gt : 100 , $lte : 200 } } );
D - db.posts.find({ likes : { $gte : 100 , $lte : 200 } } );
Since 100 and 200 are both inclusive, we need $gte (greater than and equal) and $lte (less than and equal).
Q 25 - In our posts collection, which command can be used to find all the posts whose author names begin lie between �A� and �C� in dictionary order?
A - db.posts.find( { post_author : { $gte : "A" , $lte : "C" } } );
B - db.posts.find( { post_author : { $gte : "C" , $lte : "A" } } );
C - db.posts.find( { post_author : { $gt : "A" , $lt : "C" } } );
D - This type of search is not supported by MongoDB. $lt and $gt operators are applicable only for numeric values.
The $gt, $lt and related operators can be applied for string manipulations too. They work in the same manner as they would work on numeric values.

    44 Lectures 
     3 hours 

 Arnab Chakraborty

    54 Lectures 
     5.5 hours 

 Eduonix Learning Solutions

    44 Lectures 
     4.5 hours 

 Kaushik Roy Chowdhury

    40 Lectures 
     2.5 hours 

 University Code

    26 Lectures 
     8 hours 

 Bassir Jafarzadeh

    70 Lectures 
     2.5 hours 

 Skillbakerystudios
 Print
 Add Notes
 Bookmark this page