MongoDB Developer Certification – Practice tests

1. A collection in MongoDB is a group of:

 Related documents

 Databases

 Schema

 Rows

Explanation:

Answer: (a) Explanation: A collection in MongoDB is a group of related documents.

2. Select the correct query to find all the users whose age is greater than 18.

 db.users.find()

 db.users.find({age >18})

 db.users.find({age: {$gt : 18}})

 db.users.find({age: {$lt : 18}})

Explanation:

Answer: (c) Explanation: The db.users.find({age: {$gt : 18}}) query is used to find all the users whose age is greater than 18.

3. Select the correct query to isplay user age in the descending order.

 db.users.find().sort({age:1})

 db.users.find().limit()

 db.users.find()

 db.users.find().sort(age:-1)

Explanation:

Answer: (d) Explanation: The db.users.find().sort(age:-1) query is used to display user age in the descending order.

4. You want to return maximum 5 matching documents that will return with only the _id, name, and address fields. Which of the following queries will you use?

 db.users.find( { age: { $gt: 18 } }, { name: 1, address: 1 } ).limit(5)

 db.users.find( { age: { $gt: 18 } }, { name: 1, address: 1 } ).limit(15)

 db.users.find( { age: { $lt: 18 } }, { name: 1, address: 1 } ).limit(5)

 db.users.find( { age: { $lt: 18 } }, { name: 1, address: 1 } ).limit(15)

Explanation:

Answer: (a) Explanation: db.users.find( { age: { $gt: 18 } }, { name: 1, address: 1 } ).limit(5) will return 5 matching documents with only the _id, name, and address fields.

5. What is a projection in MongoDB queries?

 It is the second argument in the find() method that may either specify a list of fields to return or list fields to exclude in the result documents.

 It is a condition which specifies the equality condition.

 It is the storage format to store the data into the hard disk.

 It is the query plan to optimize the query.

Explanation:

Answer: (c) Explanation: A projection in MongoDB queries is the storage format to store the data into the hard disk.

6. Which among the following is the way to access the different documents in the result set?

 Limit

 Sort

 Cursor

 Iterator

Explanation:

Answer: (c) Explanation: Cursor is a way to access the different documents in the result set.

7. What is the maximum size of a document in the MongoDB?

 16 MB

 64 MB

 32 MB

 1024 MB

Explanation:

Answer: (a) Explanation: The maximum size of a document in the MongoDB is 16 MB.

8. Which among following is not a supported index type in MongoDB?

 Unique

 Neospatial

 Geospatial

 TTL Index

Explanation:

Answer: (b) Explanation: Neospatial is not a supported index type in MongoDB.

9. Which among the following is an example of compound index in MongoDB?

 db.inventory.createIndex( { type: 1, item: 1 } )

 db.inventory.createIndex( { item: 1 } )

 db.inventory.createIndex( { type:1 } )

 All of the above

Explanation:

Answer: (a) Explanation: An example of compound index in MongoDB is db.inventory.createIndex( { type: 1, item: 1 } )

10. Which of the following commands will you use to view the query plan of the given query?

 db.collection.explain()

 cursor.explain()

 db.explain()

 Both A & B

Explanation:

Answer: (d) Explanation: db.collection.explain() and cursor.explain() are used to view the query plan of the given query.

11. What is the name of the process that routes the read request to specific shard based on the specified shard key?

 Config servers

 Router

 Mongod

 Balancer

Explanation:

Answer: (b) Explanation: The router routes the read request to the specific shard, based on the specified shard key.

12. What is the name of the process that keeps the metadata of a sharded cluster?

 Config servers

 Router

 Mongod

 Balancer

Explanation:

Answer: (a) Explanation: Config servers keep the metadata of a sharded cluster.

13. In the replica set, by default, MongoDB always reads data from a replica set’s:

 Secondary member

 Primary member

 Key

 Config server

Explanation:

Answer: (a) Explanation: In the replica set, by default, MongoDB always reads data from a replica set’s primary member.

14. Which among the following are the valid use cases to specify read preference mode?

 Backup operations

 Reduction of latency in multi-data-center deployments

 Improvement of read throughput by distributing high read-volumes

 All of the above

Explanation:

Answer: (d) Explanation: Backup operations, reduction of latency in multi-data-center deployments, and improvement of read throughput by distributing high read-volumes are the valid use cases to specify read preference mode.

15. Which of the following statements is correct about an insert operation?

 All write operations in MongoDB are atomic at the database level.

 All write operations in MongoDB are atomic at the schema level.

 All write operations in MongoDB are atomic at the collection level.

 All write operations in MongoDB are atomic at the document level.

Explanation:

Answer: (d) Explanation: All write operations in MongoDB are atomic at the document level.

16. Which is the correct query to update multiple documents in the “users” collection?

 db.users.update({ age: { $gt: 18 } },{ $set: { status: “A” } },{ multi: true })

 db.users.save({ age: { $gt: 18 } },{ $set: { status: “A” } },{ multi: true })

 db.users.update({ age: { $gt: 18 } },{ $set: { status: “A” } },{ multi: false})

 db.users.update({ age: { $gt: 18 } },{ $set: { status: “A” } })

Explanation:

Answer: (a) Explanation: db.users.update({ age: { $gt: 18 } },{ $set: { status: “A” } },{ multi: true }) updates multiple documents in the users” collection. “

17. Which among the following is the example of an upsert operation in MongoDB?

 db.users.upsert({ age: { $gt: 18 } },{ $set: { status: “A” } },{ multi: true })

 db.users.save({ age: { $gt: 18 } },{ $set: { status: “A” } },{ multi: true })

 db.users.update({ age: { $gt: 18 } },{ $set: { status: “A” } },{upsert: false})

 db.users.update({ age: { $gt: 18 } },{ $set: { status: “A” } },{upsert: true})

Explanation:

Answer: (d) Explanation: db.users.update({ age: { $gt: 18 } },{ $set: { status: “A” } },{upsert: true}) is the example of an upsert operation in MongoDB.

18. What is the default write concern in MongoDB?

 Journaled

 Replica Acknowledged

 Acknowledged

 Unacknowledged

Explanation:

Answer: (c) Explanation: The default write concern in MongoDB is Unacknowledged.

19. In a replica set, all write operations go to the set’s primary that applies the write operation and then records the operations in a file called:

 WAL

 Commit Log

 HFile

 Oplog

Explanation:

Answer: (d) Explanation: In a replica set, all write operations go to the set’s primary that applies the write operation and then records the operations in a file called oplog.

20. What is the minimum and maximum size of oplog in 64-bit Linux system?

 1GB and 10 GB

 1GB and 50 GB

 10GB and 50GB

 2GB and 10GB

Explanation:

Answer: (b) Explanation: The minimum and maximum size of oplog in 64-bit Linux system is 1GB and 50 GB.

21. What is the name of default storage engine in MongoDB?

 WiredTiger

 MMAPV1

 MMAPV2

 MMAPV3

Explanation:

Answer: (b) Explanation: MMAPV1s the default storage engine in MongoDB.

22. Which of the following examples select all documents in the inventory collection where the value of the type field is either ‘food’ or ‘snacks’?

 db.inventory.find( { type: { $in: [ food”

 db.inventory.find({$or: [ { type:food”}

 Both of the above

Explanation:

Answer: (c) Explanation: Both the examples select all documents in the inventory collection where the value of the type field is either ‘food’ or ‘snacks’?

23. Which of the following commands will you use to remove multiple documents whose type field value is “Book”?

 db.inventory.remove( { type : “Book” }, 1 )

 db.inventory.remove( { type : “Book” }, false )

 db.inventory.remove( { type : “Book” }, true )

 None of the above

Explanation:

Answer: (c) Explanation: The db.inventory.remove( { type : “Book” }, true ) command lets you remove multiple documents whose type field value is “Book”.

24. What is the name of the specification to store and retrieve files that exceed the BSON-document size limit of 16MB?

 Chunks

 Files

 GridFS

 Oplog file

Explanation:

Answer: (c) Explanation: GridFS stores and retrieves files that exceed the BSON-document size limit of 16MB.

25. In MongoDB, document size cannot be more than 16 MB because:

 BSON cannot contain more than 16 MB

 MongoDB stores the data as 16 MB block

 A single document cannot use excessive amount of RAM or, during transmission, excessive amount of bandwidth

 All of the above

Explanation:

Answer: (c) Explanation: In MongoDB, document size cannot be more than 16 MB because a single document cannot use excessive amount of RAM or, during transmission, excessive amount of bandwidth.

26. ObjectId is a 12-byte BSON type, in which the last 3 bytes represent:

 The Process ID

 The seconds since the Unix epoch

 The machine identifier

 A 3-byte counter, starting with a random value

Explanation:

Answer: (d) Explanation: ObjectId is a 12-byte BSON type, in which the last 3 bytes represents a counter starting with a random value

27. Which among following data types is supported by BSON and not in JSON?

 Long

 String

 Binary data

 Boolean

Explanation:

Answer: (c) Explanation: Binary data type is supported by BSON and not in JSON.

28. Which of the following is a utility of MongoDB used for taking backups?

 Mongodump

 MongoStore

 Mongo Export

 Mongorestore

Explanation:

Answer: (a) Explanation: Mongodump is used for back ups in MongoDB.

29. Which of the following commands captures and returns the counts of database operations by type, such as insert, query, update, and delete?

 mongostat

 mongotop

 Column stat

 serverStatus

Explanation:

Answer: (a) Explanation: mongostat captures and returns the counts of database operations by type, such as insert, query, update, and delete.

30. Which of the following command queries the amount of storage used, the quantity of data contained in the database, object, collection, and index counters?

 mongostat

 mongotop

 dbStats

 serverStatus

Explanation:

Answer: (c) Explanation: dbStats queries the amount of storage used, the quantity of data contained in the database, object, collection, and index counters.

31. Which among the following command returns an overview of your replica set’s status?

 replSetGetStatus

 mongostat

 mongotop

 serverStatus

Explanation:

Answer: (a) Explanation: replSetGetStatus returns an overview of your replica set’s status.

32. Which of the following monitoring tools can you install and configure to monitor a MongoDB cluster?

 Motop

 Gangila

 Nagios

 All of the above

Explanation:

Answer: (d) Explanation: Motop, Gangila, and Nagios can be installed to monitor a MongoDB cluster.

33. Which of the following statement is true about a capped collection?

 Capped collections guarantee preservation of insertion order

 Capped collections allow updates that fit the original document size that ensures a document does not change its location on disk

 Capped collections automatically remove the oldest documents in the collection without requiring any scripts or explicit remove operations

 All of the above

Explanation:

Answer: (d) Explanation: Capped collections guarantee preservation of insertion order, allow updates that fit the original document size, and automatically remove the oldest documents in the collection.

34. Which of the following syntax is used converting a non-capped collection to a capped collection?

 db.runCommand({“convertToCapped”: “mycoll”, size: 100000});

 db.runCommand({“convertingToCapped”: “mycoll”, size: 100000});

 db. convertToCapped ({size: 100000});

 None of the above

Explanation:

Answer: (a) Explanation: db.runCommand({“convertToCapped”: “mycoll”, size: 100000}); is used to convert a non-capped to a capped collection.

35. Which of the following is the recommended step to optimize query performance?

 Create Indexes to Support Queries

 Limit the Number of Query Results to Reduce Network Demand

 Use $hint to Select a Particular Index

 All of the above

Explanation:

Answer: (d) Explanation: To optimize query performance, create indexes, limit the number of queries, and use $hint.

36. What is Journaling in MongoDB?

 If mongod stops unexpectedly, the program can recover everything written to the journal

 A Write ahead log file

 All of the above

 None of the above

Explanation:

Answer: (c) Explanation: Journaling in MongoDB is if mongod stops unexpectedly, the program can recover everything written to the journal. It is also a Write ahead log file.

37. Which of the following are a supported authentication mechanism in MongoDB?

 Challenge and response mechanism (SCRAM-SHA-1)

 LDAP proxy authentication

 x509 certificate authentication

 All of the above

Explanation:

Answer: (d) Explanation: Challenge and response, LADP proxy authentication, and x509 certificate are supported authentication mechanisms in MongoDB.

38. Which of the following methods are supported in MongoDB for performing aggregation operations?

 Aggregate pipeline

 Map-reduce function

 Aggregate methods and commands

 All of the above

Explanation:

Answer: (d) Explanation: Aggregate pipeline, Map-reduce, and aggregate methods and commands are supported in MongoDB for performing aggregation operations.

39. Which of following statements is true about aggregation pipeline MongoDB?

 An aggregation pipeline is a framework for performing aggregation tasks modeled on the concept of data processing pipelines.

 The pipeline provides efficient data aggregation using native operations within MongoDB and is the preferred method for data aggregation in MongoDB.

 A and B

 Aggregation pipeline is a collection of specific data aggregation operations that support a number of common data aggregation functions.

Explanation:

Answer: (c) Explanation: An aggregation pipeline performs aggregation tasks modeled on the concept of data processing pipelines and provides efficient data aggregation using native operations within MongoDB.

40. Which of the following statements is correct about MapReduce operations in MongoDB?

 In general, MapReduce operations have two phases: a map stage that processes each document and emits one or more objects for each input document, and reduce phase that combines the output of the map operation.

 MapReduce uses custom JavaScript functions to perform the map and reduce operations.

 MapReduce is less efficient and more complex than the aggregation pipeline.

 All of the above

Explanation:

Answer: (d) Explanation: All three statements are correct.

41. Which of the following statements is correct about mongoose in MongoDB?

 It is a PHP library to connect with MongoDB

 It is Java library to connect with MongoDB

 It is used for modeling your application data in node.js

 It is Python library to connect with MongoDB

Explanation:

Answer: (c) Explanation: Mongoose is used for modeling your application data in node.js.

42. Which of the following syntax is used for retrieving documents in MongoDB using Java code?

 DBCollection.find();

 DBCollection.findAll(query, update, options)

 DBCollection.findOne()

 DBCollection.find(); and DBCollection.findOne()

Explanation:

Answer: (d) Explanation: DBCollection.find(); and DBCollection.findOne() are used to retrieve documents in MongoDB using Java code.

43. Which of the following syntax is used for updating a collection in MongoDB using Java code?

 DBCollection.update();

 DBCollection.updateCollection(query, update, options)

 DBCollection.update(query, update, options)

 DBCollection.updateCollection();

Explanation:

Answer: (c) Explanation: DBCollection.update(query, update, options) is used for updating a collection in MongoDB using Java code.

44. Which among the following syntax is used to delete a collection in MongoDB using Java code?

 DBCollection.remove();

 DBCollection.remove(DBObject);

 DBCollection.removeCollection();

 DBCollection.deleteCollection();

Explanation:

Answer: (b) Explanation: DBCollection.remove(DBObject) is used to delete a collection in MongoDB using Java code.

45. Which among the following syntax is used to create a reference for “Test” collection in Java?

 db.getCollection(“”);

 db.getCollection(“mycol”)

 db.getTestCollection()

 db.getCollection(“test”);

Explanation:

Answer: (d) Explanation: The db.getCollection(“test”); syntax is used to create a reference for “Test” collection in Java.

46. What kind of database is MongoDB?

 Graph Oriented

 Document Oriented

 Key Value Pair

 Column Based

Explanation:

Answer: (b) Explanation: MongoDB is a document oriented database.

47. A collection and a document in MongoDB is equivalent to which of the SQL concepts respectively?

 Table and Row

 Table and Column

 Column and Row

 Database and Table

Explanation:

Answer: (a) Explanation: A collection and a document in MongoDB is equivalent to table and row.

48. Which of the following statements is correct about MongoDB?

 MongoDB uses JSON format to represent documents.

 MongoDB supports collection joins.

 MongoDB supports some of the SQL functions.

 MongoDB supports geospatial indexes.

Explanation:

Answer: (d) Explanation: MongoDB supports geospatial indexes.

49. Which of the following is a valid MongoDB JSON document?

 {}

 { “user_id”=1, “user_name”=”Joe Sanders”, “occupation”=[“engineer”,”writer”] }

 { “user_id”:1; “user_name”:”Joe Sanders”; “occupation”:[“engineer”,”writer”] }

 { “user_id”:1, “user_name”:”Joe Sanders”, “occupation”:[ “occupation1″:”engineer”, “occupation2″:”writer” ] }

Explanation:

Answer: (a) Explanation: {} represents a valid MongoDB JSON document.

50. Which of the following statements is the correct explanation of MongoDB processes?

 mongod.exe is the shell process and mongo.exe is the actual database process.

 mongo.exe is the shell process and mongod.exe is the actual database process.

 mongos.exe is the MongoDB server process needed to run databases.

 mongodump.exe can be used to import database backup dumps.

Explanation:

Answer: (b) Explanation: mongo.exe is the shell process and mongod.exe is the actual database process.

51. Consider collection posts which has the 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?

 db.posts.find({},{_id:0, post_text:1})

 db.posts.findOne({post_text:1})

 db.posts.finOne({},{post_text:1})

 db.posts.finOne({},{_id:0, post_text:1})

Explanation:

Answer: (d) Explanation: db.posts.finOne({},{_id:0, post_text:1}) retrieves ONLY the key named post_text from the first document retrieved.

52. Which of the following statements is incorrect about the find and findOne operations in MongoDB?

 find() returns all the documents in a collection whereas findOne() retrieves only the first one.

 find() and findOne() returns cursors to the collection documents.

 findOne() returns the actual first document retrieved from a collection.

 find.limit(1) is not the same query as findOne().

Explanation:

Answer: (b) Explanation: find() and findOne() returns cursors to the collection documents

53. In a collection containing 100 post documents, what purpose does the db.posts.find().skip(5).limit(5) command serve?

 Skip and limit nullify each other. Hence, it returns the first five documents.

 Skips the first five documents and returns the sixth document five times.

 Skips the first five documents and returns the next five.

 Limits the first five documents and then return them in the reverse order

Explanation:

Answer: (c) Explanation: The db.posts.find().skip(5).limit(5) command skips the first five documents and returns the next five.

54. Which of the following verbosity mode is not supported by the MongoDB explain() method?

 queryPlanner

 executionStats

 allPlansExecution

 customExecutionStats

Explanation:

Answer: (d) Explanation: customExecutionStats is not supported by the MongoDB explain() method

55. In which default mode does the explain() command run?

 queryPlanner

 executionStats

 allPlansExecution

 customExecutionStats

Explanation:

Answer: (a) Explanation: The explain() command runs on the queryPlanner mode.

56. Which of the following tags in a replica set configuration specify the operations to be read from the node with the least network latency?

 primaryPreferred

 secondaryPreferred

 nearest

 netLatency

Explanation:

Answer: (c) Explanation: nearest specifies the operations to be read from the node with the least network latency.

57. How long does it take for MongDB writes to be written to the journal?

 60 s

 100 ms

 1 s

 100 s

Explanation:

Answer: (b) Explanation: MongDB writes are written to the journal within 100 ms.

58. Which of the following statements is true about sharding?

 Sharding is enabled at the database level

 Creating a sharded key automatically creates an index on the collection using that key

 We cannot change a shard key directly/automatically once it is set up

 A sharded environment does not support sorting functionality since the documents lie on various mongod instances

Explanation:

Answer: (b) Explanation: Creating a sharded key automatically creates an index on the collection using that key.

59. What is the maximum size of a MongoDB document?

 2 MB

 16 MB

 12 MB

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

Explanation:

Answer: (b) Explanation: The maximum size of a MongoDB document is 16 MB.

60. What is the maximum size of Index Key Limit and Number of Indexes per collection?

 64 bytes and 1024 indexes

 12 mega bytes and 64 indexes

 1024 bytes and 64 indexes

 1024 bytes and unlimited indexes

Explanation:

Answer: (c) Explanation: The maximum size of Index Key Limit and Number of Indexes per collection is 1024 bytes and 64 indexes.

  • Ask Question