-
rs.add("<hostname>")
-
replicaSetAdd("<hostname>")
-
rs.insert("<hostname>")
-
replica.add("<hostname>")
- restore
- backup
- mongobackup
- mongodump
-
db.citizens.select('WHERE age >= 21')
-
db.citizens.where('age >= 21')
-
db.citizens.find('WHERE age >= 21')
-
db.citizens.find({age: {$gte: 21}})
- data
- documents
- fields
- rows
-
getDateTime(_id)
-
_id.createDate()
-
_id.getTimestamp()
-
_id.getDateTime()
- myCursor.hasNext()
- myCursor.sort()
- myCursor.next()
- myCursor.find()
-
db.users.find({_id: 1})
-
db.users.seek({_id: 1})
-
db.users.query({_id: 1})
-
db.query.users({_id: 1})
-
--type jsonArray
-
--json
-
--type json
-
--jsonArray
- mongo
- mongod
- mongoconnect
- dbconnect
- db.customers.find({lastName: 'smith'}).explain()
- db.customers.find({lastName: 'smith'}).perf()
- db.customers.find({lastName: 'smith'}).plan()
- db.customers.find({lastName: 'smith'}).usedIndex()
Q11. Suppose your aggregation pipeline terminated with an exception referring to exceeded memory limit. What is the best way to resolve the issue?
- 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.
- db.deleteUser("user")
- db.removeUser("user") DEPRECATED
- db.remove("user")
- db.dropUser("user")
- once the primary has been down for 10 minutes
- once the primary reboots
- immediately
- after the administrator reboots the primary
-
--setParameter authenticationMechanisms=GSSAPI
-
--setAuthentication=GSSAPI
-
--setParam auth=K
-
--setAuth method=Kerberos
- 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.
-
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}})
- 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?
-
db.restaurants.createIndex({location: "2dsphere"})
-
db.restaurants.geospatial({location: "2dsphere"})
-
db.restaurants.createIndex("2dsphere":"location")
-
db.restaurants.createIndex({geospatial: "location"})
-
db.customers.findmatch ({"jobs":"secretary"})
-
db.customers.find ({"jobs:secretary"})
-
db.customers.find ({"jobs":["secretary"]})
-
db.customers.find ({"jobs":"secretary"})
-
db.customers.find({}, {skip: 5, limit: 10})
-
db.customers.find({}.page(5).take(10))
-
db.customers.find({}).skip(5).take(10)
-
db.customers.find({}).skip(5).limit(10)
-
db.customers.createIndex({firstName, lastName})
-
db.customers.createTextIndex({firstName, lastName})
-
db.customers.createIndex({firstName: "text", lastName: "text"})
-
db.customers.createText({firstName: 1, lastName: 1})
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?
-
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})
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.
- 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.
- They do not have to use the same operators.
- You do not need to structure the database to support them.
- They autogenerate reports.
- They run faster than indexed queries.
- every 2 minutes
- every 5 seconds
- every 2 seconds
- every 10 seconds
-
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()
- 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.
- 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.
- mongorestore
- mongoi
- upload
- mongoimport
- 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
- 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")
- 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
-
db.customers.add({name: "Bob"})
-
db.customers.save({name: "Bob"})
-
db.customers.create({name: "Bob"})
-
db.customers.new({name: "Bob"})
-
_id
-
_name
- ObjectId
- mongoDB is schema-less so no field is required
- 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?
-
db.persons.find().sort({lastName: -1}}
-
db.persons.find().sort({lastName: 1}}
-
db.persons.find().sort({lastName: ascending}}
-
db.persons.find().sort({lastName: $asc}}
- restore
- read/write
- dbadmin
- delete collections
-
db.customers.delete({_id: 1});
-
db.customers.drop({_id: 1});
-
db.drop.customers({_id: 1});
-
db.customers.remove({_id: 1});
-
db.customers.remove({}).indexes();
-
db.customers.remove({});
-
db.customers.drop();
-
db.customers.delete();
- primary
- arbiter
- secondary
- backup
Q49. 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();
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?
- Use the replaceMany() command instead
- Use the updateMulti() command instead
- Use the updateMany() command instead
- Set the global multi option to True
- 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?)
-
db.members.aggregate([ {$match: {gender: "Female"}}, {$group: {_id: {city: "$city"}, number: {$sum: 1}}}, {$sort :{number: -1}}])
-
db.members.find({$match: {gender: "Female"}}, {$group: {_id: {city: "$city"}, number: {$sum: 1}}}.$sort ({number: -1})
-
db.members.find([ {$match: {gender: "Female"}}, {$group: {_id: {city: "$city"}, number: {$sum: 1}}}, {$sort :{number: -1}}])
-
db.members.aggregate([ {$match: {gender: "Female"}}, {$sort :{number: -1}}])
- wireTiger mode
- executionStats mode
- queryPlanner mode
- allPlansExecution mode
-
db.person.find({exists: 'homePhone'});
-
db.person.exists({homePhone: true});
-
db.person.find({homePhone: {$exists: true}});
-
db.person.has('homePhone');
- mongodb
- mongo-daemon
- daemon
- mongod
Q56. You have just secured your previously unsecured MongoDB server, but the server is still not requiring authentication. What is the best option?
- Restart the
mongod
process. - Issue the
secure()
command. - Issue the
mongoimport
command. - Issue the
authenticate()
command.
- MongoDB does not allow ad hoc queries; all queries require an index.
- Ad hoc queries are allowed only in the paid version.
- Ad hoc queries are allowed only through the ad hoc command.
- MongoDB allows ad hoc queries.
- allows you to do a calculation on the results
- allows you to run queries on the server
- allows you to select which fields should be in the return data
- allows you to format the results for a display
-
dropDatabase()
-
removeAll()
-
clear()
-
deleteDatabase()
-
-db=null
-
--shell-only
-
--free
-
-nodb
-
Use db.collection.set({$_id:pretty})
-
Create a second index
-
Use db.collection.format(numeric)
-
Use $_id = value
-
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
- mongo
- mongo-s
- shell
- mongo-shell
-
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()
- node 'list.js'
- exec('list.js)
- run('list.js)
- load('list.js)
- 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.
Q68. 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.
- Create a text index on the field and do a $text Query.
- Create an 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.
- index
- Name
-
_id
- row number
- Create a user account.
- Register online.
- Create a data directory.
- Establish security credentials.
- as a properly formatted JSON array
- as YAML
- as plain text
- as a BSON object
- db.size()
- db.info()
- db.memory()
- db.stats()
- db.createUser({})
- db.insert({user: 1})
- db.customers.newUser({})
- db.newUser({})
- JSON (JavaScript Object Notation)
- BSON (Binary JSON)
- ORM (object relational mode)
- MBF (MongoDB binary format)
Q76. Which projection shows only the FirstName and lastName fields of a document in the customers collection?
-
db.customers.find({}, {firstName: 1, lastName: 1})
-
db.customers.find({}, {_id:0, firstName: 1, lastName: 1})
-
db.customers.find({_id: 0, year: 1, maek: 1, model: 1})
-
db.customers.find({}).project({firstName: 1, lastName: 1})
- database
- field
- no
- document
Q78. What should the priority of a member be in order to prevent it from becoming the primary in replica set?
- 1
- null
- 0
- -1
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.
- input
- output
- to
- onError
- JSON
- integers
- strings
- XML
- Use the -d option.
- Use the mongooverwrite command instead of mongoimport.
- Use the -drop option.
- Drop the database manually before importing.
- upload
- mongorestore
- mongoi
- mongoimport
Q84. 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} })