linkedin-skill-assessments-quizzes

MongoDB

Q1. Which command adds members to the replica set from MongoDB shell?

Q2. Which MongoDB shell command should you use to back up a database?

Q3. Which shell query displays all citizens with an age greater than or equal to 21?

Q4. What does a MongoDB collection consist of?

Q5. Given an ObjectId in _id, how do you get the time it was created?

Q6. Given a cursor named myCursor, which command returns a boolean value?

Q7. Which command returns a specific document in the user’s collection?

Q8. To import a JSON array into Mongo, what flags are needed with MongoDBimport?

Q9. Choose the shell command that connects to a MongoDB database.

Q10. In the MongoDB shell, how can you tell if an index was used with a query?

Q11. Suppose your aggregation pipeline terminated with an exception referring to exceeded memory limit. What is the best way to resolve the issue?

Q13. What the primary database in a replica set fails, when does failover begin?

Q14. What is the correct option to set up Kerberos when starting MongoDBd?

Q15. What is the purpose of an arbiter in a replica set?

Q16. You want to know how many types of items you have in each category. Which query does this?

Q17. To restrict the number of records coming back from a query, which command should you use?

Q18. You have a collection named restaurants with the geographical information stored in the location property, how do you create a geospatial index on it?

Q19. How do you find documents with a matching item in an embedded array?

Q20. Which query bypasses the first 5 customers and returns the next 10?

Q21. How do you create a text index?

Q22. Assuming you have customers collection with a firstName and lastName field, which is the correct MongoDB shell command to create an index on lastName, then firstName both ascending?

Q23. One of the documents in your collection has an _id based upon an older database design and you want to change it. You write an update command to find the document and replace the _id but the _id isn’t changed. How should you fix the issue?

Q24. A compound index allows you to _ ?

Reference

Q25. Why are ad-hoc queries useful?

Q26. How often do the members of a replica set send heartbeats to each other?

Q27. Which command returns all of the documents in the customers collection?

Q28. Given a cursor named myCursor, pointing to the customers collection, how to you get basic info about it?

Q29. What is true about indexes?

Q30. What is the preferred format to store geospatial data in MongoDB?

Q31. Which programming language is used to write MongoDB queries? (Alternative: In the MongoDB shell, what programming language is used to make queries?)

Q32. You have two text fields in your document and you’d like both to be quickly searchable. What should you do?

Q33. To import a CSV file into MongoDB, which command should you issue?

Q34. In an MongoDB mapReduce command, the reduce function should _.

Q35. On a newly created collection, which field will have an index?

Q36. You have a collection of thousands of students. You’d like to return the second set of 20 documents from the sorted collection. What is the proper order in which to apply the operations?

Q37. You would like the stats() command to return kilobytes instead of bytes. Which command should you run?

Q38. You want to modify an existing index. What is the best way to do this?

Q39. You need to delete the index you created on the description field. Which command will accomplish this?

Q40. You would like to know how many different categories you have. Which query will best get the job done?

Note: count() works with find(…) but length works with distinct

Q41. From the MongoDB shell, how do you create a new document in the customers collection?

Q42. Which field is required of all MongoDB documents?

Q43. A MongoDB instance has at least what three files?

Q44. You’d like a set of documents to be returned in last name, ascending order. Which query will accomplish this?

Q45. What is NOT a standard role in MongoDB?

Reference

Q46. Which MongoDB shell command deletes a single document?

Note: db.collection.remove() is deprecated in the new mongosh. Use db.collection.deleteOne() or db.collection.deleteMany().

References: db.collection.remove() db.collection.delete()

Q47. Using the MongoDB shell, how do you remove the customer collection and its indexes?

Q48. By default, applications direct their read operations to which member of the replica set?

Q49. You need to get the names of all the indexes on your current collection. What is the best way to accomplish this?

Note: An alternative method in the mongosh shell is listIndexes()

Reference

Q50. You are going to do a series of updates to multiple records. You find setting the multi option of the update() command too tiresome. What should you do instead?

Note: An alternative method for db is .update()

Reference

Q51. To cleanly shut down MongoDB, what command should you use from the MongoDB shell?

Q52. Given a customer collection which includes fields for gender and city, which aggregate pipeline shows the number of female customers in each city? (Alternative: How can you view the execution performance statistics for a query?)

Note: If you want to analyze the performance of a query use .explain(“executionStats”)

Reference

Q53. When no parameters are passed to explain(), what mode does it run in?

Q54. What is the correct query to find all of the people who have a home phone number defined?

Q55. Which file in the MongoDB directly holds the MongoDB daemon?

Q56. You have just secured your previously unsecured MongoDB server, but the server is still not requiring authentication. What is the best option?

Q57. What is the most accurate statement regarding MongoDB and ad hoc queries?

Note: You don’t need an index to perform ad hoc queries. Only pick one choice Reference

Q58. In MongoDB, what does a projection do?

Q59. To remove a database and all of its records from MongoDB, what operator should you use?

Q60. What option can be passed to start the MongoDB shell without connecting to a database?

Q61. How can you improve the appearance of the output JSON that contains the _id?

Reference:

Q62. What happens to a Replica set oplog if it runs out of memory?

Argument:

Why “The oplog will be saved on one of the secondary servers.” is wrong:

MongoDB applies database operations on the primary and then records the operations on the primary’s oplog. The secondary members then copy and apply these operations in an asynchronous process. All replica set members contain a copy of the oplog, in the local.oplog.rs collection, which allows them to maintain the current state of the database.

Reasoning behind the right answer:

The oplog (operations log) is a special capped collection that keeps a rolling record of all operations that modify the data stored in your databases.

Unlike other capped collections, the oplog can grow past its configured size limit to avoid deleting the majority commit point.

Q63. MongoDB ships with a variety of files. Which file runs the MongoDB shell?

Note: mongosh is the new mongo shell, mongo is deprecated.

Starting in MongoDB v5.0, mongosh replaces mongo as the preferred shell.

[Reference:] (https://www.mongodb.com/docs/mongodb-shell/)

Q64. How can you view the execution performance statistics for a query?

Q65. From the MongoDB shell, how do you execute a JavaScript file named list.js?

Q66. Which MongoDB shell query will sort the customer’s collection by name descending?

Q67. Suppose you are using the mongoimport command to import personnel data and there is a unique index on the email field. What happens when there are duplicate emails in the import?

Note: By default, mongoimport continues an operation when it encounters duplicate key and document validation errors.

Reference

Q68. You have a collection with millions of documents. Each time you attempt to sort. MongoDB runs out of memory. What might help?

Q69. You need to be able to quickly find a word in a text field. What should you do?

Argument: You need a text index in order to perform a $text query on a field. $text query uses the text index under the hood

References: $text query Text index

Q70. Which field is always included in a projection unless specifically excluded?

Reference

Q71. After installing MongoDB on your machine, what must you do before launching Mongo?

Note: The question in case is ambiguous. In the mongo docs, on the Windows Installation section, it clearly specifies the need for creating a data directory. However, that does not seem to be the case for Unix based systems. So, that gives use the closest possible solution for a specific platform. If we extrapolate that to the question, that seems to be the most reasonable solution.

mongodb site

Q72. How does a --jsonArray file need to be structured?

Section blog

Q73. From the MongoDB shell, how do you display all of a database’s memory usage?

Q74. How do you create a new MongoDB user?

MongoDB documentation

Q75. What is the internal data structure of a MongoDB document?

MongoDB documentation JSON and BSON

Q76. Which projection shows only the FirstName and lastName fields of a document in the customers collection?

Q77. Documents in mongodb are atomic at the ___ level

MongoDB reference

Q78. What should the priority of a member be in order to prevent it from becoming the primary in replica set?

MongoDB reference

Q79. You need to add an index to the large name collection in your production database. You do not want to have disruption of service for your users and you can’t afford to have a team to do the work during after hours. What should you do?

MongoDB reference

Concurrency Changed in version 4.2.

MongoDB uses an optimized build process that obtains and holds an exclusive lock on the specified collection at the start and end of the index build. All subsequent operations on the collection must wait until createIndex() releases the exclusive lock. createIndex() allows interleaving read and write operations during the majority of the index build.

For more information on the locking behavior of createIndex(), see Index Builds on Populated Collections.

Q80. When using aggregation $convert. which is not a parameter?

MongoDB reference

Q81. All tag values in tag sets must be _.

MongoDB reference

Q82. When using the mongoimport command, how can you drop the database before importing?

Argument: There is no -d option in the docs (https://www.mongodb.com/docs/database-tools/mongoimport/#options.)

Note: Assuming you are asked to drop a collection instead while importing, the use the --drop option.

Q83. To import a CSV file into MongoDB, which command should you issue?

Q84. A critical record must be replicated to the two other servers in the set. Which query guarantees that it is inserted as desired?

MongoDB reference

Q85. What is the name of the default file used to configure MongoDB?

MongoDB reference

Q86. After using the dropIndexes() command on your collection, one index remains.What can you do to drop the the remaining index?

MongoDB reference

Q87. To scale horizontally, what does MongoDB use?

MongoDB reference

Q88. Your database collection holds web session information. One field, lastActivity, holds the timestamp of when the user was last active. You want to delete the user session after 30 minutes of inactivity. What is your best option?

MongoDB reference

Q89. In the MongoDB shell, how can you tell if an index was used with a query?

Q90. You need to be able to quickly find a word in a text field. What should you do?

Q91. What is the name of the default file used to configure MongoDB?

Q92. You have a collection named restaurants with the geographical information stored in the location property, how do you create a geospatial index on it?

Q93. What happens to a Replica set oplog if it runs out of memory?

Q94. Using the MongoDB shell, how do you remove the customer collection and its indexes?

Q95. What is the primary advantage of using MongoDB as a NoSQL database over traditional relational databases?

Explanation : MongoDB’s primary advantage as a NoSQL database over traditional relational databases is its schema flexibility.

Q96. What is a Replica Set in MongoDB?

Q97. Which command is used to create a new database in MongoDB?

Q98. What is the default port number for MongoDB?

Q99. Which of the following is a BSON data type in MongoDB?

Q100. What is the purpose of an index in MongoDB?

Q101. Which operator is used for equality in MongoDB queries?

Q102. What is the role of the mongod process in MongoDB?

Q103. Which method is used to remove a document from a collection in MongoDB?

Q104. What is a GridFS in MongoDB?

Q105. Which aggregation stage in MongoDB is used to group documents by a specified expression and apply an accumulator expression to each group?

Q106. What is sharding in MongoDB?

Q107. Which operation is used to update a document in MongoDB?

Q108. What is a TTL index in MongoDB?

Q109. Which command is used to limit the number of documents returned in a MongoDB query?

Q110. What is a compound index in MongoDB?

Q111. Which operator is used to perform a logical OR operation in MongoDB queries?

Q112. What is a covered query in MongoDB?

Q113. Which method is used to create an index in MongoDB?

Q114. What is a compound shard key in MongoDB?

Q115. What is the purpose of the mongos process in MongoDB?