MongoDB Skill Test Linkedin Question Answers
1. Which of the following operation is used to switch to new database mydb?
- use db
- use mydbs
- use dbs
- use mydb
2. To restrict the number of
records coming back from a query, which command should you use?
- take
- limit
- max
- skip
3. 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.geospatial({location: "2dsphere"})
- db.restaurants.CreateIndex("2dsphere":"location")
- db.restaurants.CreateIndex({geospatial: "location"})
- db.restaurants.CreateIndex({location: "2dsphere"})
4. How do you find documents with
a matching item in an embedded array?
- db.customers.find ({"jobs":["secretary"]})
- db.customers.find ({"jobs":"secretary"})
- db.customers.findmatch ({"jobs":"secretary"})
- db.customers.find ({"jobs:secretary"})
5. Which query bypasses the first
5 customers and returns the next 10?
- db.customers.find({}).skip(5).take(10)
- db.customers.find({}).skip(5).limit(10)
- db.customers.find({}, {skip: 5, limit: 10})
- db.customers.find({}.page(5).take(10))
6. How do you create a text index?
- db.customers.createIndex({firstName: "text", lastName: "text"})
- db.customers.createText({firstName: 1, lastName: 1})
- db.customers.createIndex({firstName, lastName})
- db.customers.createTextIndex({firstName, lastName})
7. 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.createIndex({lastName:1, firstName: 1})
- db.customers.addIndex({lastName:"ASC", firstName: "ASC"})
- db.customers.newIndex({lastName:1, firstName:1})
8. 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?
- You can't. Once set, the _id field cannot be changed.
- Use the updateOne() command instead.
- Set the replace option to true.
- Use the replaceOne() command instead.
9. A compound index allows you to
_ ?
- Use more than one field per index.
- Combine fields in different collations.
- Calculate interest quickly.
- Accomplish nothing, since compound indexes aren't allowed in Mongo.
10. Why are ad-hoc queries useful?
- They do not have to use the same operators.
- They autogenerate reports.
- They run faster than indexed queries.
- You do not need to structure the database to support them.
11. When using aggregation
$convert. which is not a parameter?
- input
- output
- to
- onError
12. 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 parallel = true.
- Use the createIndex() command with the option background = true.
- Use the createIndex() command.
13. What should the priority of a
member be in order to prevent it from becoming the primary in replica set?
- null
- 0
- 1
- -1
14. Documents in mongodb are
atomic at the ___ level
- database
- no
- document
- field
15. 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, year: 1, maek: 1, model: 1})
- db.customers.find({}, {_id:0, firstName: 1, lastName: 1})
- db.customers.find({}).project({firstName: 1, lastName: 1})
16. What is the preferred format
to store geospatial data in MongoDB?
- GeoJSON
- BSON
- Latitude, longitude
- XML
17. What is true about indexes?
- They speed up reads and writes.
- They speed up read access while slowing down writes.
- They secure the database from intruders.
- They speed up write access while slowing down reads.
18. Given a cursor named myCursor,
pointing to the customers collection, how to you get basic info about it?
- myCursor.info()
- myCursor.explain()
- myCursor.stats()
- myCursor.dump()
19. Which command returns all of
the documents in the customers collection?
- db.customers.all();
- db.find().customers();
- db.customers.find();
- db.customers.show();
20. 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
21. 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.
22. What is the correct option to
set up Kerberos when starting MongoDBd?
- --setParam auth=K
- --setAuth method=Kerberos
- --setParameter authenticationMechanisms=GSSAPI
- --setAuthentication=GSSAPI
23. 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
24. What is the recommended way to
delete a user?
- db.remove("user")
- db.dropUser("user")
- db.deleteUser("user")
- db.removeUser("user") DEPRECATED
25. Suppose your aggregation
pipeline terminated with an exception referring to exceeded memory limit. What
is the best way to resolve the issue?
- Set allowDiskUse to true.
- Set useMemory to twice amount indicated in exception.
- Switch a 64 bit instance of MongoDB.
- Increase the memory of the MongoDB server.
26. 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)
27. How do you create a new
MongoDB user?
- db.insert({user: 1})
- db.createUser({})
- db.customers.newUser({})
- db.newUser({})
28. From the MongoDB shell, how do you display all of a database's memory
usage?
- db.memory()
- db.stats()
- db.size()
- db.info()
29. How does a --jsonArray file
need to be structured?
- as YAML
- as plain text
- as a properly formatted JSON array
- as a BSON object
30. 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.
31. Which field is always included
in a projection unless specifically excluded?
- Name
- _id
- row number
- index
32. 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 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.
33. You have a collection with
millions of documents. Each time you attempt to sort. MongoDB runs out of
memory. What might help?
- Pass the --more-memory option.
- Create an index on the field you are sorting.
- Use the purge operator before the sort.
- Return the entire collection and sort on the client.
34. 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 doesn't import the bad document but does import the rest.
- The import command prompts you to correct the bad record.
- The import command aborts without importing any records.
- The import command imports records upto but not including the record, and then aborts.
35. What is the equivalent command
in MongoDB for the following SQL query?SELECT * FROM posts WHERE author like
"%john%"
- db.posts.find( { author: /john/ } )
- db.posts.find( { author: {$like: /john/} } )
- db.posts.find( { $like: {author: /john/} } )
- db.posts.find( { author: /^john^/ } )
36. From the MongoDB shell, how do
you execute a JavaScript file named list.js?
- run('list.js)
- load('list.js)
- node 'list.js'
- exec('list.js)
37. 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()
- 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}}]).number()
38. MongoDB ships with a variety
of files. Which file runs the MongoDB shell?
- mongo
- mongo-s
- shell
- mongo-shell
39. What happens to a Replica set
oplog if it runs out of memory?
- The oplog is capped collection and can't run out of memory
- The MongoDB instance will fail
- The oplog will be saved on one of the secondary servers.
- The oplog will stop recording logging information
40. 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
41. You have just secured your
previously unsecured MongoDB server, but the server is still not requiring
authentication. What is the best option?
- Issue the mongoimport command.
- Issue the authenticate() command.
- Restart the mongod process.
- Issue the secure() command.
42. What is the most accurate
statement regarding MongoDB and ad hoc queries?
- Ad hoc queries are allowed only through the ad hoc command.
- MongoDB allows ad hoc queries.
- MongoDB does not allow ad hoc queries; all queries require an index.
- Ad hoc queries are allowed only in the paid version.
43. In MongoDB, what does a
projection do?
- allows you to select which fields should be in the return data
- allows you to format the results for a display
- allows you to do a calculation on the results
- allows you to run queries on the server
44. To remove a database and all
of its records from MongoDB, what operator should you use?
- clear()
- dropDatabase()
- removeAll()
- deleteDatabase()
45. What option can be passed to
start the MongoDB shell without connecting to a database?
- -db=null
- --shell-only
- --free
- -nodb
46. Which command adds members to
the replica set from MongoDB shell?
- rs.add("<hostname>")
- replicaSetAdd("<hostname>")
- rs.insert("<hostname>")
- replica.add("<hostname>")
47. Which MongoDB shell command
should you use to back up a database?
- restore
- backup
- mongobackup
- mongodump
48. 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({age: {$gte: 21}})
- db.citizens.find('WHERE age >= 21')
49. What does a MongoDB collection
consist of?
- data
- documents
- fields
- rows
50. Given an ObjectId in _id, how
do you get the time it was created?
- getDateTime(_id)
- _id.createDate()
- _id.getTimestamp()
- _id.getDateTime()
51. 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"})
52. 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
53. 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")
54. 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.
55. 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")
56. 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
57. 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
58. 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
59. To import a CSV file into
MongoDB, which command should you issue?
- mongorestore
- mongoi
- upload
- mongoimport
60. 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.
61. What is the correct query to
find all of the people who have a home phone number defined?
- db.person.find({exists: 'homePhone'});
- db.person.exists({homePhone: true});
- db.person.find({homePhone: {$exists: true}});
- db.person.has('homePhone');
62. When no parameters are passed
to explain(), what mode does it run in?
- wireTiger mode
- executionStats mode
- queryPlanner mode
- allPlansExecution mode
63. Given a customer collection
which includes fields for gender and city, which aggregate pipeline shows the
number of female customers in each city?
- 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}}])
64. 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
65. By default, applications
direct their read operations to which member of the replica set?
- primary
- arbiter
- secondary
- backup
66. 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();
67. To cleanly shut down MongoDB,
what command should you use from the MongoDB shell?
- quit()
- exit()
- db.shutdownServer()
- db.shutdown()
68. Using the MongoDB shell, how
do you remove the customer collection and its indexes?
- db.customers.remove({}).indexes();
- db.customers.remove({});
- db.customers.drop();
- db.customers.delete();
69. Which file in the MongoDB
directly holds the MongoDB daemon?
- mongodb
- mongo-daemon
- daemon
- mongod
70. What is NOT a standard role in
MongoDB?
- restore
- read/write
- dbadmin
- delete collections
71. 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
72. 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()
73. No limit.Depends on RAM MongoDB
Queries can return specific fields of documents which also include user-defined
__________ functions.
- C
- C++
- Javascript
- All of the mentioned
74. Which field is required of all
MongoDB documents?
- _id
- _name
- ObjectId
- mongoDB is schema-less so no field is required
75. 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});
76 To import a JSON array into
Mongo, what flags are needed with MongoDBimport?
- --type jsonArray
- --json
- --type json
- --jsonArray
77. 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})
78. ___________ provides
statistics on the per-collection level.
- mongotop
- mongosniff
- mongofiles
- mongooplog
79. 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}}
80. Choose the shell command that
connects to a MongoDB database.
- mongo
- mongod
- mongoconnect
- dbconnect
81. Which of the following is not
part of _id?
- Timestamp
- machineID
- processID
- documentID
82. You want to know how many
types of items you have in each category. Which query does this?
- 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}})
83. 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})
84. What is the maximum size of a
MongoDB document?
- 10MB
- 2MB
- 16MB
- 12MB
85. 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
86. Given a cursor named myCursor,
which command returns a boolean value?
- myCursor.hasNext()
- myCursor.sort()
- myCursor.next()
- myCursor.find()
87. Dynamic schema in MongoDB
makes ____________ easier for applications.
- polymorphism
- inheritance
- encapsulation
- None of the mentioned
88. MongoDB scales horizontally
using _________ for load balancing purpose.
- Partitioning
- Sharding
- Replication
- None of the mentioned
89. A query _______ consists of a
combination of query, sort, and projection specifications.
- stats
- shape
- plan
- All of the mentioned
90. CRUD operation in mognodb
are______
- create read update delete
- create read update local
- create read update drop
- None above
91. Collection is a group of
MongoDB ___________?
- Database
- Document
- Field
- None of the above