MongoDB - Skill Assignment Quiz
Q1. Which command adds members to the replica set from MongoDB shell?
-
rs.add("<hostname>")
-
replicaSetAdd("<hostname>")
-
rs.insert("<hostname>")
-
replica.add("<hostname>")
Q2. Which MongoDB shell command should you use to back up a database?
- restore
- backup
- mongobackup
- mongodump
Q3. Which shell query displays all citizens with an age greater than or equal to 21?
-
db.citizens.select('WHERE age >= 21')
-
db.citizens.where('age >= 21')
-
db.citizens.find('WHERE age >= 21')
-
db.citizens.find({age: {$gte: 21}})
Q4. What does a MongoDB collection consist of?
- data
- documents
- fields
- rows
Q5. Given an ObjectId in _id, how do you get the time it was created?
-
getDateTime(_id)
-
_id.createDate()
-
_id.getTimestamp()
-
_id.getDateTime()
Q6. Given a cursor named myCursor, which command returns a boolean value?
- myCursor.hasNext()
- myCursor.sort()
- myCursor.next()
- myCursor.find()
Q7. Which command returns a specific document in the user's collection?
-
db.users.find({_id: 1})
-
db.users.seek({_id: 1})
-
db.users.query({_id: 1})
-
db.query.users({_id: 1})
Q8. To import a JSON array into Mongo, what flags are needed with MongoDBimport?
-
--type jsonArray
-
--json
-
--type json
-
--jsonArray
Q9. Choose the shell command that connects to a MongoDB database.
- mongo
- mongod
- mongoconnect
- dbconnect
Q10. In the MongoDB shell, how can you tell if an index was used with a query?
- db.customers.find({lastName: 'smith'}).explain()
- db.customers.find({lastName: 'smith'}).perf()
- db.customers.find({lastName: 'smith'}).plan()
- db.customers.find({lastName: 'smith'}).usedIndex()
Q10. In the MongoDB shell, how can you tell if an index was used with a query?
- Set useMemory to twice amount indicated in exception.
- Switch a 64 bit instance of MongoDB.
- Increase the memory of the MongoDB server.
- Set allowDiskUse to true.
Q11. What the primary database in a replica set fails, when does failover begin?
- once the primary has been down for 10 minutes
- once the primary reboots
- immediately
- after the administrator reboots the primary
Q12. What is the correct option to set up Kerberos when starting MongoDBd?
-
--setParameter authenticationMechanisms=GSSAPI
-
--setAuthentication=GSSAPI
-
--setParam auth=K
-
--setAuth method=Kerberos
Q13. What is the purpose of an arbiter in a replica set?
- It monitors replica set and sends email in case of failure
- It casts the tie-breaking vote in an election.
- It holds a backup copy of the database.
- It reboots the failed server.
Q14. What is the purpose of an arbiter in a replica set?
-
db.product.group({_id: "$category", count: {$sum:1}})
-
db.product.aggregate($sum: {_id: "$category", count: {$group:1}})
-
db.product.aggregate($group: {_id: "$category", count: {$sum:1}})
-
db.product.aggregate($count: {_id: "$category", count: {$group:1}})
Q15. To restrict the number of records coming back from a query, which command should you use?
- take
- limit
- max
- skip
Q16. You have a collection named restaurants with the geographical information stored in the location property, how do you create a geospatial index on it?
-
db.restaurants.createIndex({location: "2dsphere"})
-
db.restaurants.geospatial({location: "2dsphere"})
-
db.restaurants.createIndex("2dsphere":"location")
-
db.restaurants.createIndex({geospatial: "location"})
Q17. How do you create a text index?
-
db.customers.createIndex({firstName, lastName})
-
db.customers.createTextIndex({firstName, lastName})
-
db.customers.createIndex({firstName: "text", lastName: "text"})
-
db.customers.createText({firstName: 1, lastName: 1})
Q18. 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?
-
db.customers.createIndex("lastName, firstName, ASC")
-
db.customers.addIndex({lastName:"ASC", firstName: "ASC"})
-
db.customers.newIndex({lastName:1, firstName:1})
-
db.customers.createIndex({lastName:1, firstName: 1})
Q19. 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.
Q20. A compound index allows you to _ ?
- Calculate interest quickly.
- Accomplish nothing, since compound indexes aren't allowed in Mongo.
- Use more than one field per index.
- Combine fields in different collations.
Q21. Which command returns all of the documents in the customers collection?
-
db.customers.all();
-
db.find().customers();
-
db.customers.find();
-
db.customers.show();
Q22. What is the preferred format to store geospatial data in MongoDB?
- Latitude, longitude
- XML
- GeoJSON
- BSON
Q23. 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
Q24. To import a CSV file into MongoDB, which command should you issue?
- mongorestore
- mongoi
- upload
- mongoimport
Q25. 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
Q26. 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")
Q27. 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.
Q28. 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")
Q29. 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"})
Q30. You'd like a set of documents to be returned in last name, ascending order. Which query will accomplish this?
-
db.persons.find().sort({lastName: -1}}
-
db.persons.find().sort({lastName: 1}}
-
db.persons.find().sort({lastName: ascending}}
-
db.persons.find().sort({lastName: $asc}}
Q31. Which MongoDB shell command deletes a single document?
-
db.customers.delete({_id: 1});
-
db.customers.drop({_id: 1});
-
db.drop.customers({_id: 1});
-
db.customers.remove({_id: 1});
Q32. By default, applications direct their read operations to which member of the replica set?
- primary
- arbiter
- secondary
- backup
Q33. You need to get the names of all the indexes on your current collection. What is the best way to accomplish this?
-
db.people.getName();
-
db.people.reIndex({names: 1});
-
db.people.getIndexKeys();
-
db.people.getIndexes();
Q34. 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?
- Use the replaceMany() command instead
- Use the updateMulti() command instead
- Use the updateMany() command instead
- Set the global multi option to True
Q35. To cleanly shut down MongoDB, what command should you use from the MongoDB shell?
- quit()
- exit()
- db.shutdownServer()
- db.shutdown()
Q36. How can you improve the appearance of the output JSON that contains the _id?
-
Use db.collection.set({$_id:pretty})
-
Create a second index
-
Use db.collection.format(numeric)
-
Use $_id = value
Q37. How can you view the execution performance statistics for a query?
-
db.performance.members.aggregate([ {$match: {gender: "Female"}}, {$group: {_id:{city:"$city"}, number: {$sum: 1}}}, {$sort : {number: -1}}])
-
db.members.aggregate([ {$match: {gender: "Female"}}, {$group: {_id: {city: "$city"}, number:{$sum:1}}}, {$sort: {number:-1}}]).explain("executionStats")
-
db.members.aggregate([ {$match: {gender: "Female"}}, {$group:{_id: {city: "$city"}, number: {$sum: 1}}}, {$sort: {number: -1}}]).explain()
-
db.members.aggregate([ {$match: {gender: """Female"""}}, {$group: {_id: {city: """$city"""}, number: {$sum:1}}}, {$sort: {number: -1}}]).number()
Q38. 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})
Q39. You have a collection with millions of documents. Each time you attempt to sort. MongoDB runs out of memory. What might help?
- Use the purge operator before the sort.
- Return the entire collection and sort on the client.
- Pass the --more-memory option.
- Create an index on the field you are sorting.
Q40. 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.
Q41. What is the internal data structure of a MongoDB document?
- JSON (JavaScript Object Notation)
- BSON (Binary JSON)
- ORM (object relational mode)
- MBF (MongoDB binary format)
Q42. Documents in mongodb are atomic at the ___ level
- database
- field
- no
- document
Q43. What should the priority of a member be in order to prevent it from becoming the primary in replica set?
- 1
- null
- 0
- -1
Q44. 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.
Q45. To import a CSV file into MongoDB, which command should you issue?
- upload
- mongorestore
- mongoi
- mongoimport
Q46. A critical record must be replicated to the two other servers in the set. Which query guarantees that it is inserted as desired?
-
db.inventory.insert({ prodid: "tab1122", qty : 10}, { writeConcern: { w: 2, wtimeout: 5000} })
-
db.inventory.insert({ prodid: "tab1122", qty : 10}, { writeConcern: { j: true} })
-
db.inventory.insert({ prodid: "tab1122", qty : 10}, { writeConcern: { w: 2, j:false, wtimeout: 5000} })
-
db.inventory.insert({ prodid: "tab1122", qty : 10}, { writeConcern: { w: 2, j:true, wtimeout: 5000} })
Q47. After using the dropIndexes() command on your collection, one index remains.What can you do to drop the the remaining index?
- Use dropIndexes({all:1}) with the all parameter.
- The required_id index cannot be deleted.
- Call dropIndex({"id":1}) to force its removal.
- Call dropIndex({"id"}) to force its removal.
READY TO GET STARTED?
Are you ready
Let’s Make Something Amazing Together



Need help? Contact our experts
Tell us about your project




