M201 MongoDB Performance – All Chapters Quiz Answer

MongoDB Performance | Chapter 1 – Introduction Quiz Answer

  

Introduction to MongoDB Performance

Problem:
Which of the following statements is/are true?
  • Indexes will be a major topic covered in this course.
  • Quizzes and labs each make up 50% of your final grade in the class.
  • The content of this course is more geared for DBAs than developers.
  • This course will take a deep dive into how different types of computer hardware can be used to improve database performance.

Hardware Considerations & Configurations Part 2

Problem:
Regarding the performance implications, which of the following
statements are correct?
  • MongoDB does not benefit from adding more RAM to your servers.
  • Disk RAID architecture can impact the performance of your MongoDB
    deployment.
  • Switching from HDDs to SSDs does not bring a benefit to the
    performance of MongoDB.
  • CPU availability impacts the performance of MongoDB, especially if
    using the WiredTiger storage engine.
 
 

M201 Overview

Problem:
Which of the following will be covered in this course?
  • Indexes
  • Explain plans
  • Optimizing the aggregation pipeline
  • Tuning with the profiler

MongoDB Performance Chapter 2 MongoDB Indexes Quiz Answer

 
Introduction to Indexes
Problem:
Which of the following statements regarding indexes are true?
  • Indexes are used to increase the speed of our queries.
  • The _id field is automatically indexed on all collections.
  • Indexes can decrease write, update, and delete performance.
  • mIndexes reduce the number of documents MongoDB needs to examine to satisfy a query.
 

Single Field Indexes Part 2

Problem:
Which of the following queries can use an index on the zip field?
  • db.addresses.find()
  • db.addresses.find( { zip : 55555 } )
  • db.addresses.find( { city : “Newark”, state : “NJ” } )

Sorting with Indexes

Problem:
Given the following schema for the products collection:
 
{
  “_id”: ObjectId,
  “product_name”: String,
  “product_id”: String
}
 
And the following index on the products collection:
 
{ product_id: 1 }
 
Which of the following queries will use the given index to perform the sorting of the returned documents?
  • db.products.find({}).sort({ product_id: -1 })
  • db.products.find({}).sort({ product_id: 1 })
  • db.products.find({ product_name: ‘Soap’ }).sort({ product_id: 1
    })
  • db.products.find({ product_name: ‘Wax’ }).sort({ product_name: 1
    })
  • db.products.find({ product_id: ’57d7a1′ }).sort({ product_id: -1
    })
 
 

Multikey Indexes

Problem:
Given the following index:
{ name: 1, emails: 1 }
When the following document is inserted, how many index entries will be created?
 
{
  “name”: “Beatrice McBride”,
  “age”: 26,
  “emails”: [
      “[email protected]”,
      “[email protected]”,
      “[email protected]
  ]
}
  • 1
  • 2
  • 3
  • 4
 
 

Partial Indexes

Problem:
Which of the following is true regarding partial indexes?
  • Partial indexes support compound indexes.
  • Partial indexes don’t support a uniqueness constraint.
  • Partial indexes represent a superset of the functionality of sparse
    indexes.
  • Partial indexes can be used to reduce the number of keys in an
    index.
 

Text Indexes

Problem:
Which other type of index is mostly closely related to text indexes?
  • Multi-key indexes
  • Partial indexes
  • Single-key indexes
  • Compound indexes

Collations

Problem:
Which of the following statements are true regarding collations on
indexes?
  • We can define specific collations in an index
  • Collations allow the creation of case insensitive indexes
  • MongoDB only allows collations to be defined at collection
    level
  • Creating an index with a different collation from the base collection
    implies overriding the base collection collation.

MongoDB Performance Chapter 3 – Index Operations Quiz Answer

 

Building Indexes

Problem:
Which of the following are true of index build operations?
  • Background index builds take longer to complete than foreground index builds.
  • Background index builds block reads and writes to the collection
    being indexed.
  • Foreground index builds block all reads and writes to the collection being indexed.
  • Foreground index builds block all reads and writes to the
    database that holds the collection being indexed.
  • Background index builds do not impact the query performance of the MongoDB deployment while running.
 

Query Plans

Problem:
Which of the following is/are true concerning query plans?
  • If an index can’t be used, then there is no query plan for that query.
  • When query plans are generated, for a given query, every index generates at least one query plan.
  • MongoDB’s query optimizer is statistically based, where collection heuristics are used to determine which plan wins.
  • Query plans are cached so that plans do not need to be generated and compared against each other every time a query is executed.
 

Understanding Explain Part 2

Problem:
With the output of an explain command, what can you deduce?
  • The index used by the chosen plan
  • All the available indexes for this collection
  • The estimation of the cardinalities of the distribution of the values
  • If a sort was performed by walking the index or done in memory
  • All the different stages the query needs to go through with details about the time it takes, the number of documents processed and – returned to the next stage in the pipeline

Forcing Indexes with Hint

Problem:
What is the method that forces MongoDB to use a particular index?
  • hint()
  • index()
  • force()
  • suggest()
 

Resource Allocation for Indexes Part 3

Problem:
Which of the following statements apply to index resource
allocation?
  • For the fastest processing, we should ensure that our indexes fit
    entirely in RAM
  • Indexes are not required to be entirely placed in RAM, however
    performance will be affected by constant disk access to retrieve
    index information.
  • Index information does not need to completely allocated in RAM
    since MongoDB only uses the right-end-side to the index b-tree,
    regardless of the queries that use index.
 
 

Basic Benchmarking Part 2

Problem:
What type of strategy and tools should we be using to performance
benchmark a MongoDB installation?
  • Mongo shell to test read performance
  • Test transfer ratio using mongodump
  • Publicly available tools, including correct database
    variations

MongoDB Performance | Chapter 4 – CRUD Optimization

 

Optimizing your CRUD Operations

Problem:
When building indexes to service your queries, which of the following
is the general rule of thumb you should keep when ordering your index
keys?
 
Note, use the following definitions to for this question:
  • equality: indexed fields on which our queries will do equality
    matching
  • range: indexed fields on which our queries will have a range
    condition
  • sort: indexed fields on which our queries will sort on
  • equality, range, sort
  • sort, range, equality
  • sort, equality, range
  • equality, sort, range
  • range, sort, equality
  • range, equality, sort
 

Covered Queries

Problem:
Given the following indexes:
 
{ _id: 1 }
{ name: 1, dob: 1 }
{ hair: 1, name: 1 }
Which of the following queries could be covered by one of the given
indexes?
  • db.example.find( { name : { $in : [ “Alfred”, “Bruce” ] } }, { name :
    1, hair : 1 } )
  • db.example.find( { name : { $in : [ “Bart”, “Homer” ] } }, {_id : 0,
    hair : 1, name : 1} )
  • db.example.find( { _id : 1117008 }, { _id : 0, name : 1, dob : 1 }
    )
  • db.example.find( { name : { $in : [ “Bart”, “Homer” ] } }, {_id : 0,
    dob : 1, name : 1} )
 
 

Regex Performance

Problem:
Given the following index:
 
> db.products.createIndex({ productName: 1 })
 
And the following query:
 
> db.products.find({ productName: /^Craftsman/ })
 
Which of the following are true?
  • The query will do an index scan.
  • The query will need to do a collection scan.
  • The query will likely need to look at all index keys.
  • The query would match a productName of “Screwdriver – Craftsman
    Brand”
 
 

Insert Performance

Problem:
Which of the following decreases the write performance of your MongoDB
cluster?
  • Adding indexes
  • Upgrading to MongoDB 3.4
  • Increasing the number of members we acknowledge writes from
 

Data Type Implications Part 2

Problem:
Why is it important to maintain the same data type for fields across
different documents?
  • Because it aligns well with cosmetic shapes of documents
  • To avoid application data consistency problems
  • It helps to simplify the client application logic
  • It’s just a best practice; all drivers will deal with data type
    issues by default

Aggregation Performance

Problem:
With regards to aggregation performance, which of the following are
true?
  • When $limit and $sort are close together a very performant top-k sort
    can be performed
  • You can increase index usage by moving $match stages to the end of
    your pipeline
  • Passing allowDiskUsage to your aggregation queries will seriously
    increase their performance
  • Transforming data in a pipeline stage prevents us from using indexes
    in the stages that follow

MongoDB Performance | Chapter 5 – Performance on Clusters Quiz
Answer

 

Performance Considerations in Distributed Systems Part 2

Problem:
From a performance standpoint, when working with a distributed database
it’s important to consider…
  • Routed Queries
  • Latency
  • Reading from secondaries only
 

Increasing Write Performance with Sharding Part 2

Problem:
Which of the following is/are true?
  • Ordered bulk operations are faster than unordered.
  • Vertical scaling is generally cheaper than horizontal scaling.
  • Picking a good shard key is one of the most important parts of
    sharding.

Reading from Secondaries

Problem:
Should you ever read from secondaries on a sharded cluster?
  • Select this answer and read the detailed answer section for more
    information.
 

Replica Sets with Differing Indexes Part 3

Problem:
Which of the following conditions apply when creating indexes on
secondaries?
  • These indexes can only be set on secondary nodes
  • A secondary should never be allowed to become primary
  • We can create specific indexes on secondaries, even if they are not
    running in standalone mode
 

Aggregation Pipeline on a Sharded Cluster

Problem:
What operators will cause a merge stage on the primary shard for a
database?
  • $out
  • $group
  • $lookup

MongoDB Performance

Final Exam Quiz Answer

Question 1)
Which of these statements is/are true?
  • A collection scan has a logarithmic search time.
  • Covered queries can sometimes still require some of your documents to
    be examined.
  • You can index multiple array fields in a single document with a single
    compound index.
  • Write concern has no impact on write latency.
  • Creating an ascending index on a monotonically increasing value
    creates index keys on the right-hand side of the index tree.
Question 2)
Which of the following statements is/are true?
  • Indexes can decrease insert throughput.
  • It’s important to ensure that your shard key has high
    cardinality.
  • Indexes can be walked backwards by inverting their keys in a sort
    predicate.
  • Partial indexes can be used to reduce the size requirements of the
    indexes.
  • It’s important to ensure that secondaries with indexes that differ
    from the primary not be eligible to become primary.
Question 3)
Which of the following statements is/are true?
  • MongoDB indexes are markov trees.
  • Collations can be used to create case insensitive indexes.
  • By default, all MongoDB user-created collections have an _id
    index.
  • It’s common practice to co-locate your mongos on the same machine
    as your application to reduce latency.
  • Background index builds block all reads and writes to the database
    that holds the collection being indexed.
Question 4)
Which of the following statements is/are true?
  • Indexes can solve the problem of slow queries.
  • When you index on a field that is an array it creates a partial
    index.
  • Under heavy write load you should scale your read throughput by
    reading from secondaries.
  • Indexes are fast to search because they’re ordered such that you
    can find target values with few comparisons.
  • On a sharded cluster, aggregation queries using $lookup will require
    a merge stage on a random shard.
Question 5)
Which of the following statements is/are true?
  • By default, the explain() command will execute your query.
  • If no indexes can be used then a collection scan will be
    necessary.
  • Compound indexes can service queries that filter on a prefix of the
    index keys.
  • Compound indexes can service queries that filter on any subset of the
    index keys.
  • Query plans are removed from the plan cache on index creation,
    destruction, or server restart.
Question 6)
Which of the following statements is/are true?
  • Indexes can only be traversed forward.
  • The ideal ratio between nReturned and totalKeysExamined is 1.
  • An index doesn’t become multikey until a document is inserted that
    has an array value.
  • Running performance tests from the mongo shell is an acceptable way to
    benchmark your database.
  • You can use the –wiredTigerDirectoryForIndexes option to place
    your indexes on a different disk than your data.
Question 7)
Given the following indexes:
{ categories: 1, price: 1 }
{ in_stock: 1, price: 1, name: 1 }

The following documents:
 
{ price: 2.99, name: “Soap”, in_stock: true, categories: [‘Beauty’,
‘Personal Care’] }
{ price: 7.99, name: “Knife”, in_stock: false, categories: [‘Outdoors’]
}
And the following queries:
db.products.find({ in_stock: true, price: { $gt: 1, $lt: 5 } }).sort({
name: 1 })
db.products.find({ in_stock: true })
db.products.find({ categories: ‘Beauty’ }).sort({ price: 1 })
Which of the following is/are true?
  • Index #1 would provide a sort to query #3.
  • Index #2 can be used by both query #1 and #2.
  • Index #2 properly uses the equality, sort, range rule for query #1.
  • There would be a total of 4 index keys created across all of these
    documents and indexes.

Leave a Comment