- Choose the best description of why MongoDB performs well on a non heterogeneous cluster:
Answers:
• New databases will be assigned a primary on the «most available» shard where most available means the shard with the least amount of data on it
• Each shard in MongoDB is its own mongod, an isolated MongoDB in itself (Every shard in MongoDB is its own mongod)
• By Implementing replicating sets
• The query routers distribute the load to compensate for shard endpoint resources
- You are setting up replication for a mongodb cluster and you get the following error «no replset config has been received».
Choose the most probable reason:
Answers:
• You have not run rs.initiate() in the master node
• You need to run reconfig in the master node
• You have not run rs.initiate() in the master node and rs.slaveOk() on the secondaries
• Your rs.add(«….») is missing the quotation marks
- Which of the following is true about replica set?
Note: There may be more than one right answer.
Answers:
• It’s a group of servers with one primary.
• It’s a group of servers with many primaries.
• It’s a group of servers with one secondary.
• It’s a group of servers with many secondaries.
- How many members a replica set can have?
Answers:
• Up to 10
• Up to 25
• Up to 50
• Up to 100
- Point out the correct statement :
Answers:
• A rollback does not occur if the write operations replicate to another member of the replica set before the primary steps down
• Secondaries that can not keep up with the throughput of operations on the former primary, decrease the size and impact of the rollback
• Fault tolerance is an effect of replica set size, but the relationship is not direct
• None of the mentioned
- What is the minimum nodes required for replica?
Answers:
• 2
• 3
• 1
• No minimum required
- Sometimes the failover process may require a ____ during operation.
Answers:
• savepoint
• rollback
• commit
• None of the above
- What is the use of profiler?
Answers:
• Profiler is used to execute every operation used in the query.
• Profiler is used to show the performance characteristics of every operation against the database.
• Profiler is used to optimize the data model of the database.
• None of the above
- Which of following helps analyze a query?
Answers:
• understand
• analyze
• explain
• executionInfo
- Choose the statement that best describes the query below:
db.myCol.find().sort({$natural:-1}).limit(50);
Answers:
• Will sort in descending numerical order
• Returns the last 50 entries in descending order
• Fails as the limit operator should precede the sort operator
• Returns the last 50 entries in ascending order
- Which of the following are atomic operations in MongoDB?
Note: There may be more than one right answer.
Answers:
• .findOne
• .findById
• .remove
• .findAndModify
- Which of the following information is captured by the Database Profiler in MongoDB ?
Answers:
• Read operations
• Write operations
• Cursor Operations
• All of the above
- Choose the best statement «why aggregation queries out perform mapreduce for small datasets».
Answers:
• MapReduce functions are written in JavaScript
• Aggregation is able to use indexes and internal optimizations
• MapReduce is optimised for sharded input collections
• There is a JavaScript lock so a mongod server can only execute one JavaScript function at a time
- MongoDB is a process collection of documents using (…) operations
Answers:
• Hbase
• Hive
• Map-reduce
• None of the mentioned
- Which of the following are correct index types?
Answers:
• Compound
• Geospatial
• TTL
• All of the above.
- Which of the following best describes the concept of Aggregations in MongoDB ?
Answers:
• It’s a method for storing data across multiple machines. MongoDB uses it to support deployments with very large data sets and high throughput operations.
• It’s the process of synchronizing data across multiple servers, providing redundancy and increases data availability, with multiple copies of data on different database servers.
• It’s the operation that process data records and return computed results, by grouping values from multiple documents together, so that it can perform a variety of operations on the grouped data to return a single result.
• It’s the process on which MongoDB preallocates data files to reserve space and avoid file system fragmentation when you setup the server.
- Why is sharding necessary?
Answers:
• In replication all writes go to master node.
• Memory can’t be large enough when active data set is big.
• Local disk is not big enough.
• Vertical scaling is too expensive.
• All of the above
- If the address data is frequently retrieved with the name information,how will you modify the following schema representing one to one relationship with referencing ?
{
_id: «joe»,
name: «Joe Bookreader»
}
{
patron_id: «joe»,
street: «123 Fake Street»,
city: «Faketon»,
state: «MA»,
zip: «12345»
}
Answers:
• {
_id: «joe»,
name: «Joe Bookreader»,
address: {
street: «123 Fake Street»,
city: «Faketon»,
state: «MA»,
zip: «12345»
}
}
• {
_id: «joe»,
name: «Joe Bookreader»,
address-> {
street: «123 Fake Street»,
city: «Faketon»,
state: «MA»,
zip: «12345»
}
}
• {
_id: «joe»,
name: «Joe Bookreader»,
address:: {
street: «123 Fake Street»,
city: «Faketon»,
state: «MA»,
zip: «12345»
}
}
• All of the above
- For the query below
db.collection.find( { x: 5 } ).sort( { z: 1} )
Choose the best index to support the query
Answers:
• { x: 1 }
• { x: 1, y:1, z: 1 }
• { x: 1, z: 1 }
• { x: 1, z: -1 }
- Which of the following command can be used to check the size of a collection named user?
Answers:
• db.stats({collection: user})
• db.user.stats()
• db.user.findStats()
• db.user.find({stats:1})
- Choose the best description of the query below:
db.users.find ({ «name» : /m/i } ).pretty()
Answers:
• case insensitive match query
• case sensitive match query with pretty italics
• case insensitive query for those users whose name has ‘m’
• case insensitive query for those users whose name starts with ‘m’
- Regarding MongoDB sharding, choose the correct statement:
Answers:
• MongoDB distributes data, or shards, at the collection level
• To shard a document, you need to select a shard key
• MongoDB divides the shard key values into replica sets
• All of the mentioned
- Regarding data modeling in MongoDB, which of the following is correct ? Answers:
• The key decision in designing data models for MongoDB applications revolves around the structure of documents and how the application represents relationships between data.
• There are two tools that allow applications to represent these relationships: references and embedded documents.
• When designing data models, always consider the application usage of the data (i.e. queries, updates, and processing of the data) as well as the inherent structure of the data itself.
• All of the above
- Which of the following is a correct command to insert a document in a database called album and collection called songs?
Answers:
• db.album.songs.insert( { title: «Roar», artist: «Katy Perry» } )
• db.album.insert( { title: «Roar», artist: «Katy Perry» } )
• album.songs.insert( { title: «Roar», artist: «Katy Perry» } )
• db.songs.insert( { title: «Roar», artist: «Katy Perry» } )
- Which of the following may be a use case where MongoDB is a good fit?
Answers:
• When you need to prevent data duplication
• When you need strong referential integrity
•When you need to store data with nested arrays
• When you need to optimise resources
- Choose the best commands to clone a collection to a sharded cluster from a developer machine.
Answers:
• Both mongoimport and mongoexport and copy the file to the destination server with correct authentication
• mongodump and mongorestore to export the data in bson format
• Both mongoimport and mongoexport and copy the file to the destination server. In a securely configured network, you shouldn’t be able to access both developer and production database from the same machine
• Both mongoimport and mongoexport and copy the file to the destination server with correct authentication
- Regarding MongoDB sharding, choose the incorrect statement:
Answers:
• For hash-based sharding, MongoDB divides the data set into ranges determined by the shard key values to provide hash based partitioning.
• cloud-based providers may only allow users to provision smaller instance.
• For hash based partitioning, MongoDB computes a hash of a field’s value, and then uses these hashes to create chunks.
• All of the above
- For a collection that represents type A
{ “field1” : “val1”, “field2” : “val2” }
Choose the best way to optimize the collection for updates if field2 is an Enumeration.
Answers:
• { “field1” : “val1”, field2 : [“val2”] }
• { field1 : [“val1”], field2: {“field3”:…} }
• { field1: {“field2”:…} , field3: {“field4”:…} }
• { “field1” : “val1”, “field2” : “val2” }
- Which of the following calls will set 1 second limit for a query?
Answers:
• .maxTime(1)
• .maxScan(1)
• .maxTimeMS(1000)
• .maxTimeMS(1)
- Which of the following methods will shut down replica set?
Answers:
• newReplica.stop();
• newReplica.stopSet();
• newReplica.stopSets();
• newReplica.downSet();
- Point out the wrong statement :
Answers:
• In all cases, you can use replication to increase read capacity
• Clients have the ability to send read and write operations to different servers
• You can also maintain copies in different data centers to increase the locality and availability of data for distributed applications
• None of the mentioned
- Why use Replication?
Answers:
• To keep your data safe
• Disaster Recovery
• Read scaling
• All of the above
- Which of the read preference modes in a replica set configuration specify the operations to be read from the node whose network latency falls within the acceptable latency window?
Answers:
• netLatency
• primaryPreferred
• nearest
• secondaryPreferred
- You have a 10G primary partition with your data in in ‘ /var/lib/mongodb/’. Choose the best option to transfer data to a larger partition:
Answers:
• Use the —dbpath parameter to point to the new partition
• Just move your folder, add symlink, then tune permissions
• Change the settings in mongod.cfg
• Change the settings in mongod.conf
- Which of the following best describes the concept of Replication in MongoDB ?
Answers:
• It’s a method for storing data across multiple machines. MongoDB uses it to support deployments with very large data sets and high throughput operations.
• It’s the process of synchronizing data across multiple servers, providing redundancy and increases data availability, with multiple copies of data on different database servers.
• It’s the operation that process data records and return computed results, by grouping values from multiple documents together, so that it can perform a variety of operations on the grouped data to return a single result.
• It’s the process on which MongoDB preallocates data files to reserve space and avoid file system fragmentation when you setup the server.
- The oplog (operations log) in MongoDB is a special capped collection that keeps a rolling record of all operations that modify the data stored in your databases. All the replica set members contain a copy of the oplog in the _____ collection.
Answers:
• oplog.rs
• local.oplog.rs
• .oplog.rs
• None of the above
- What is the difference between Sharding and Replication ?
Answers:
• Replication allows for horizontal scaling of data writes by partitioning data across multiple servers while Sharding creates additional copies of the data.
• Replication creates additional copies of the data and allows for automatic failover while Sharding allows for horizontal scaling of data writes by partitioning data across multiple servers.
• Replication allows for horizontal scaling of data writes by partitioning data across multiple servers using a replication parameter while Sharding creates additional copies of the data and allows for automatic failover using a shard key.
• Replication creates copies of the working set while Sharding distributes queries in parallel across mongod instances.
- In a shared replica set environment, w defined the level and kind of write concern. Which of the following values of w specifies ti return success only after a majority of voting members have acknowledge?
Answers:
• major
• n
• majority
• m
- Which of the following is the correct call to setup replica set?
Answers:
• newReplica = new ReplSetTest(3);
• newReplica = new ReplSetTest({nodes:3});
• newReplica = new ReplSetTest();
• newReplica = new ReplSetTest(null);
• None of the above
- Which of the following is true? Check all that applies.
Note: There may be more than one right answer.
Answers:
• A replica set is a group of mongodb instances that host the same data set.
• Replica set has only one node.
• In a replica one node is primary node that receives all write operations.
• At the time of automatic fail over or maintenance, all secondary nodes act as main node.
• Some data replicates from primary to secondary node.
- What is the default size of GridFS chunk?
Answers:
• 2 MB
• 255 kB
• 1 MB
• 16 MB
- What kind of NoSQL database is MongoDB?
Answers:
• Graph
• Key Value
• Document Oriented
• Column Oriented
- Describe the output of the following mongo shell JavaScript:
Object.keys(db.collection.findOne())
Answers:
• Defaults to the guid for objects system keys
• Lists all the collection’s keys
• Returns an error as the key space is not defined for a schema-less design
• Returns an error as you can only check for the existence of a field
- Which of the following fields does DBRefs have?
Answers:
• $ref
• $id
• $db
• All of the above
- Which of the following commands will find all the posts that have been tagged as tutorial?
Answers:
• db.posts.find({ tags: [«tutorial»] })
• db.posts.find({ $array: {tags: «tutorial»} })
• db.posts.find({ tags: «tutorial» })
• db.posts.findInArray({ tags: «tutorial» })
- The query below returns a collection of users with a projection.
db.users.find({}, {name: 1, _id : 1})
Choose the best statement that describes how to extract a collection of users with the projection that shows the creation date.
Answers:
• Project the creation date
• Projection with ObjectId.getTimestamp()
• Map the projection with ObjectId.getTimestamp()
• Aggregate the collection with ObjectId.getTimestamp()
- When should you avoid embedding one document within another in MongoDB?
Answers:
• Usability reasons
• One-to-many relationships
• ‘contains’ relationships between entities
• When there are so many embedded document updates that it becomes a bottleneck for performance
- In MongoDB, write operations are atomic at the (………..) level.
Answers:
• collection
• document
• raw
• All of the above
- Which of the following is correct for _id in MongoDB?
Answers:
• _id: ObjectId(4 bytes timestamp, 3 bytes machine id, 2 bytes process id, 3 bytes incrementer)
• _id: ObjectId(3 bytes machine id, 2 bytes process id, 3 bytes incrementer, 4 bytes timestamp)
• _id: ObjectId(2 bytes process id, 3 bytes incrementer, 4 bytes timestamp, 3 bytes machine id)
• _id: ObjectId(4 bytes timestamp, 3 bytes machine id, 3 bytes incrementer, 2 bytes process id)
• None of the Above
- Which of the following is a valid MongoDB document?
Answers:
• {«user_name:»John»}
• {}
• {«user_name»=»John»}
• {«user_name»:»John», category:[«first»:»IT», «second»:»Networking»]}
• None of the above
- Choose the statement that best describes the query below:
db.myCol.find().sort({_id:1});
Answers:
• Will sort in ascending order by _id
• Will sort oldest to newest as _id includes a date object
• Will project the id field in a natural sort
• Will sort in ascending numerical order based on the hash for the id field
- Which of following points describes the use of embedded data models?
Answers:
• One-to-many relationships.
• Many-to-many-relationships.
• To have better performance.
• One-to-many relationships. Many-to-Many relationships.
- Which option is the most suitable advantage of using embedded documents?
Answers:
• It allows reading connected data in a single request to the database.
• Saves on indexing resources
• Improves write performance as is denormalizing
• Leads to easier projection queries
- Which one of the following is a primary key in MongoDB?
Answers:
• createdAt
• updatedAt
• _id
• None of the Above
- Which of the following is correct about Capped Collections? (choose all that apply)
Note: There may be more than one right answer.
Answers:
• To make room for new documents, capped collections automatically removes the oldest documents in the collection without requiring scripts or explicit remove operations.
• High-throughput operations that insert and retrieve documents based on insertion order.
• Capped collections do not guarantee preservation of the insertion order.
• All of the above
- Which collection is used by MongoDB to store GridFS data?
Answers:
• fs.grid and fs.parts
• fs.files and fs.chunks
• fs.parts and fs.files
• None of the above
- Which of the following parameters affect ObjectId? (choose all that apply)
Note: There may be more than one right answer.
Answers:
• Internet connection
• Timestamp
• Machine ID
• Client browser’s process ID
- Which of the following cursor methods is used to select a particular index?
Answers:
• hint
• haxNext
• next
• snapshot
- Which statement best describes $allElementsTrue?
Answers:
• Evaluates an array as a set and returns true if no element in the array is false
• Evaluates an array as a set and returns true if no element in the array is null
• Evaluates an array as a set and returns true if no element in the array is false. If the array contains a nested array then it performs the same operation on the nested array
• Evaluates an array as a set and returns true if no element in the array is false. If a the array contains a nested array it does not descend into the nested array but evaluates the array at top-level
- Which aggregation option is used to specify the fields that need to be passed to the next stage of the aggregation pipeline?
Answers:
• $match
• $project
• $group
• $aggregate
- Which of the following are stages of aggregation?
Note: There may be more than one right answer.
Answers:
• $sort
• $skip
• $drop
• $limit
- Which of the following operations will write the resulting documents of the aggregation pipeline to a collection in MongoDB?
Answers:
• $in
• $out
• $output
• None of the above
- Regarding Pipeline Operators in MongoDB, which of the following is an incorrect statement? (choose all that apply)
Note: There may be more than one right answer.
Answers:
• $avg is an accumulator operator available only in the $group stage
• $avg is an accumulator operator available only in the $project stage
• $avg ignores non-numeric values
• All of the mentioned are correct statements
- Which of the following is correct syntax for creating an index?
Answers:
• db.mycol.createIndex({«title»:1})
• db.mycol.create({«title»:1})
• db.mycol.makeIndex({«title»:1})
• All of the above
- Which of the following commands will return all the posts with a number of likes greater than 100 and less than 200, including the limit values ?
Answers:
• db.posts.find({ likes : { $gt : 100, $lt : 200 } } );
• db.posts.find({ likes : { $gte : 100, $lt : 200 } } );
• db.posts.find({ likes : { $gt : 100 , $lte : 200 } } );
• db.posts.find({ likes : { $gte : 100 , $lte : 200 } } );
- When is sharding needed? (choose all that apply)
Note: There may be more than one right answer.
Answers:
• Local disk is not big enough
• Single replica set has limitation of 10 nodes
• Vertical scaling is too expensive
• Memory can’t be large enough when the active dataset is big
- Which of the following best describes the concept of Sharding in MongoDB ?
Answers:
• It’s a method for storing data across multiple machines. MongoDB uses it to support deployments with very large data sets and high throughput operations.
• It’s the process of synchronizing data across multiple servers, providing redundancy and increases data availability, with multiple copies of data on different database servers.
• It’s the operation that processes data records and returns computed results, by grouping values from multiple documents together, so that it can perform a variety of operations on the grouped data to return a single result.
• It’s the process on which MongoDB preallocates data files to reserve space and avoid file system fragmentation when you setup the server.
- Which of the following are strategies of Sharding?
Note: There may be more than one right answer.
Answers:
• Hashed
• Ranged
• Key
• All of the above
- Which of the following components exists in sharded cluster?
Answers:
• Mongos
• Shard
• Config servers
• All of the above
- Which statement is valid?
Answers:
• Sharding occurs on database level.
• Sharding occurs at the index level.
• MongoDB shards data at the collection level.
• None of the above
- A query fails to return a complete result set on a sharded cluster. Choose the most probable reason
Answers:
• You need to update the ShardVersion system property
• One of the Mongodb processes has a system lock
• All the members of the sharded cluster can not reach all the other members
• You need to increase the number of replica sets
- Which of the following is true about sharding?
Answers:
• Sharding is the method of horizontal scaling.
• Sharding allows adding maximum of 10 machines.
• Sharding is the method of vertical scaling.
• Replication and Sharding are the same.
- How many chunks can there be if the shard key cardinality is 4?
Answers:
• 1
• 2
• 3
• 4
- What do you mean by sharding?
Answers:
• Storing data records across multiple machines to meet the demands of data growth.
• Process of synchronizing data across multiple servers.
• Process of processing data records and returning computed results.
• None of the above
- How can you create index on a particular key in MongoDB?
Answers:
• db.COLLECTION_NAME.ensureIndex({ KEY: 1 })
• COLLECTION_NAME.ensureIndex({ KEY: 1 })
• db.COLLECTION_NAME.createIndex({ KEY: 1 })
• None of the Above
- What is the maximum number of Indexes per collection allowed?
Answers:
• 1024 indexes
• unlimited indexes
• 64 indexes
• No limit
- In MongoDB, a query ____ consists of a combination of query, sort, and projection specifications.
Answers:
• plan
• shape
• stats
• None of the above.
- Choose the best description for the query below
db.foo.find({
$text:{
$search:»text» }
});
Answers:
• match query for strings containing ‘text’
• match query for strings like ‘text’
• match query for tokens containing ‘text’
• match query for tokens like ‘text’
- If the value of totalKeysExamined is 30000 and the value of totalDocsExamined is 0, which option is correct?
Answers:
• The query returned 30000 documents after scanning the documents
• The query used an index to fetch the results
• The query returned 0 documents
• None of the above
- Which of the following methods allow you to insert documents into a collection?(choose all that apply)
Note: There may be more than one right answer.
Answers:
• insert
• insertSingle
• insertOne
• insertMany
- What is a covered query?
Answers:
• It uses at least some of the index
• It returns all fields in the document
• The fields used in the query are part of an index used in the query, and the fields returned in the results are in the same index
• None of the above
- The following statement is most suitable for the following aggregation stage:
«Used to select fields from the collection while aggregation».
Answers:
• $unwind
• $select
• $selectFields
• $project
- What can be done to optimize aggregation pipeline?
Answers:
• Place the $match as early in the aggregation pipeline as possible
• Place the $match as the second argument in the aggregation pipeline and place first $group
• Use $where in $match queries as part of the aggregation pipeline
• Use $text in $match stage when $match is last argument in pipeline
- Which of the following is not an aggregation operation? (choose all that apply)
Note: There may be more than one right answer.
Answers:
• Sum
• Average
• Max
• Update
• Min
• Insert
- Regarding indexing and performance in MongoDB, choose the correct statement :
Answers:
• If you only ever query on a single key in a given collection, then you need to create just multikey index for that collection
• If you sometimes query on only one key and at other times query on that key combined with a second key, then creating a compound index is more efficient than creating a single-key index
• The choice between creating compound indexes that support your queries or relying on index intersection is independent of specifics of your system
• None of the mentioned
- Which of the following expressions can not be used with aggregation?
Answers:
• $addToSet
• $pop
• $push
• $sum
- What is the maximum size of an Index key?
Answers:
• 12 mega bytes
• 16 mega bytes
• 1024 bytes
• None of the above
- Which statement best describes the query below?
db.col1.findAndModify({
query: {«name»: «val1»},
update: { $inc: { «subObj.field1»: 1 } });
Answers:
• Returns a collection of documents where name is val1
• Returns a single document where name is val1 and field1 incremented by 1 in the returned document
• Returns a single document where name is val1 and field1 is unmodified in the returned document
• Returns a collection of documents where name is val1 and field1 incremented by 1
- Under what conditions is it required to use the db.getCollection() method in the mongo shell to delete a collection?
Answers:
• If your collection name includes the null character
• If your collection name includes the underscore character
• If your collection name includes the system. Prefix
• If your collection name is greater than 160 bytes
- Suppose we have a collection of users with different ages. Which of the following calls will find the oldest person with the name John?
Answers:
• db.users.aggregate({$match: {name: «John»}}).sort({age: -1}).limit(1);
• db.users.aggregate({$select: {name: «John»}}, {$sort: {age: -1}}, {$limit: 1});
• db.users.aggregate({$select: {name: «John»}}, {$sort: {age: -1}}).limit(1);
• db.users.aggregate([{$match: {name: «John»}}, {$sort: {age: -1}}, {$limit: 1}]);
- Regarding storage in MongoDB, which of the following statements are incorrect?
Note: There may be more than one right answer.
Answers:
• When running a 32-bit build of MongoDB, the total storage size for the server, including data and indexes, is 2 gigabytes. For this reason, do not deploy MongoDB to production on 32-bit machines.
• A storage engine is the part of a database that is responsible for managing how data is stored on disk. For example, one storage engine might offer better performance for read-heavy workloads, and another might support a higher-throughput for write operations.
• MongoDB can use MMAPv1 or WiredTiger as Storage Engine
• When journaling is enabled, MongoDB stores and applies write operations in memory and in the on-disk journal after the changes are present in the data files on disk.