Q17. To restrict the number of records coming back from a query, which command should you use?
take
limit
max
skip
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?
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?
Set the replace option to true.
Use the replaceOne() command instead.
You can't. Once set, the _id field cannot be changed.
Use the updateOne() command instead.
Q24. A compound index allows you to _ ?
Calculate interest quickly.
Accomplish nothing, since compound indexes aren't allowed in Mongo.
You do not need to structure the database to support them.
They autogenerate reports.
They run faster than indexed queries.
Q26. How often do the members of a replica set send heartbeats to each other?
every 2 minutes
every 5 seconds
every 2 seconds
every 10 seconds
Q27. Which command returns all of the documents in the customers collection?
db.customers.all();
db.find().customers();
db.customers.find();
db.customers.show();
Q28. Given a cursor named myCursor, pointing to the customers collection, how to you get basic info about it?
myCursor.stats()
myCursor.dump()
myCursor.info()
myCursor.explain()
Q29. What is true about indexes?
They speed up read access while slowing down writes.
They secure the database from intruders.
They speed up reads and writes.
They speed up write access while slowing down reads.
Q30. What is the preferred format to store geospatial data in MongoDB?
Latitude, longitude
XML
GeoJSON
BSON
Q31. Which programming language is used to write MongoDB queries? (Alternative: In the MongoDB shell, what programming language is used to make queries?)
Python
JavaScript
SQL
TypeScript
Q32. You have two text fields in your document and you'd like both to be quickly searchable. What should you do?
Create a text index on each field.
MongoDB is not able to do this.
Create a compound text index using both fields.
Create a text index on one field and a single field index on the other.
Q33. To import a CSV file into MongoDB, which command should you issue?
mongorestore
mongoi
upload
mongoimport
Q34. In an MongoDB mapReduce command, the reduce function should _.
access the database
be called only when the key has a single value
access the database only to perform read operations
not access the data
Q35. On a newly created collection, which field will have an index?
the name field
the ObjectId field
the _id field
no 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?
limit, skip, sort
sort, limit, skip
limit, sort, skip
sort, skip, limit
Q37. You would like the stats() command to return kilobytes instead of bytes. Which command should you run?
db.vehicle.stats(1024)
db.vehicle.stats("kilobytes")
db.vehicle.stats(true)
db.vehicle.stats("kb")
Q38. You want to modify an existing index. What is the best way to do this?
Use the reIndex() command to modify the index.
Delete the original index and create a new index.
Call the createIndex() command with the update option.
Use the updateIndex() command.
Q39. You need to delete the index you created on the description field. Which command will accomplish this?
db.vehicle.dropIndex("description_text")
db.vehicle.dropIndex({"description":"text"})
db.vehicle.removeIndex({"description":"text"})
db.vehicle.removeIndex("description_text")
Q40. You would like to know how many different categories you have. Which query will best get the job done?
db.vehicle.distinct("category")
db.vehicle.unique("category")
db.vehicle.distinct("category").count()
db.vehicle.distinct("category").length
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?
db.customers.add({name: "Bob"})
db.customers.save({name: "Bob"})
db.customers.create({name: "Bob"})
db.customers.new({name: "Bob"})
Q42. Which field is required of all MongoDB documents?
_id
_name
ObjectId
mongoDB is schema-less so no field is required
Q43. A MongoDB instance has at least what three files?
data, namespace, and journal
namespace, journal, and log
journal, data, and database
data, log, and journal
Q44. You'd like a set of documents to be returned in last name, ascending order. Which query will accomplish this?
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?
Q51. To cleanly shut down MongoDB, what command should you use from the MongoDB shell?
quit()
exit()
db.shutdownServer()
db.shutdown()
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?)
Q62. What happens to a Replica set oplog if it runs out of memory?
The oplog will be saved on one of the secondary servers.
The oplog is capped collection and can't run out of memory
The MongoDB instance will fail
The oplog will stop recording logging information
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?
mongo
mongo-s
shell
mongo-shell
Note: mongosh is the new mongo shell, mongo is deprecated.
Starting in MongoDB v5.0,
mongosh
replaces mongo as the preferred shell.
Q65. From the MongoDB shell, how do you execute a JavaScript file named list.js?
node 'list.js'
exec('list.js)
run('list.js)
load('list.js)
Q66. Which MongoDB shell query will sort the customer's collection by name descending?
db.customers.sort({name: -1}.find({})
db.customers.sort({name: -1})
db.customers.find({}).sort({name: -1})
db.customers.find({}).sort({name: 1})
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?
The import command aborts without importing any records.
The import command imports records upto but not including the record, and then aborts.
The import command doesn't import the bad document but does import the rest.
The import command prompts you to correct the bad record.
Note: By default, mongoimport continues an operation when it encounters duplicate key and document validation errors.
Q71. After installing MongoDB on your machine, what must you do before launching Mongo?
Create a user account.
Register online.
Create a data directory.
Establish security credentials.
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.
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?
Use the reIndex() command to add the index quickly.
Use the createIndex() command with the option background = true.
Use the createIndex() command.
Use the createIndex() command with the option parallel = true.
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?
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?
Create Javascript function called via an interval timeout to delete all records older than 30 minutes.
Create a TTL index on the lastActivity field and set expireAfterSeconds to 1800.
You have to create a stored procedure.
Every time you create a new record for expired older records and delete them.
Q90. You need to be able to quickly find a word in a text field. What should you do?
Create a text index on the field and do a $text Query.
Create a single field index in descending order, and do a query for the word.
Do a $text query.
Create a $regex on the fields, and do a $regex query.
Q91. What is the name of the default file used to configure MongoDB?
mongo.config
mongod.conf
config.sys
.mdbconfig
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?