Posts

Lab 4.1

Image
In this lab you're going to use the equality, sort, range rule to determine which index best supports a given query. Given the following query: db.accounts.find( { accountBalance : { $gte : NumberDecimal(100000.00) }, city: "New York" } ) .sort( { lastName: 1, firstName: 1 } ) Which of the following indexes best supports this query with regards to the equality, sort, range rule. Choose the best answer. Answer: As per  the equality, sort, range rule below is the best option:

Lab 3.1

Image
In this lab you're going to determine which index was used to satisfy a query given its explain output. The following query was ran: > var exp = db.restaurants.explain("executionStats") > exp.find({ "address.state": "NY", stars: { $gt: 3, $lt: 4 } }).sort({ name: 1 }).hint(REDACTED) Which resulted in the following output: { "queryPlanner": { "plannerVersion": 1, "namespace": "m201.restaurants", "indexFilterSet": false, "parsedQuery": "REDACTED", "winningPlan": { "stage": "SORT", "sortPattern": { "name": 1 }, "inputStage": { "stage": "SORT_KEY_GENERATOR", "inputStage": { "stage": "FETCH", "inputStage": { "stage": "IXSCAN", &

Lab 2.2

Image
In this lab you're going to examine several example queries and determine which compound index will best service them. > db.people.find ({ "address.state" : "Nebraska" , "last_name" : /^G/, "job" : "Police officer" }) > db.people.find ({ "job" : /^P/, "first_name" : /^C/, "address.state" : "Indiana" }) .sort ({ "last_name" : 1 }) > db.people.find ({ "address.state" : "Connecticut" , "birthday" : { " $ gte" : ISODate ( "2010-01-01T00:00:00.000Z" ) , " $ lt" : ISODate ( "2011-01-01T00:00:00.000Z" ) } }) If you had to build one index on the people collection, which of the following indexes would best sevice all 3 queries? Choose the best answer. Answer: { "address.state": 1, "job": 1 } - No - As this can able t

Lab 2.1

Image
In this lab you're going to determine which queries are able to successfully use a given index for both filtering and sorting. Given the following index: {"first_name": 1, "address.state": -1, "address.city": -1, "ssn": 1} Which of the following queries are able to use it for both filtering and sorting? Check all that apply: Answer: db.people.find({ "first_name": { $gt: "J" } }).sort({ "address.city": -1 }) - No - This query doesn't use equality on the index prefix. When using an index for filtering and sorting the query must include equality conditions on all the prefix keys that precede the sort keys. Moreover, on the sort predicate it skipped the next key in the prefix "address.state". db.people.find({ "first_name": "Jessica" }).sort({ "address.state": 1, "address.city": 1 }) - Yes . This query matches with equality on the query predicate wit

Lab 1.2

Image
For this optional lab you're going to install MongoDB Compass 1.5. This lab is optional because Compass doesn't currently support all Linux distributions. While Compass, like MongoDB Enterprise, Compass is available as part of the MongoDB Enterprise Advanced subscription it's permitted to be ran outside of production environments. In order to install Compass you're going to need to head over to the MongoDB Download Center. From there the installation should be fairly straightforward. Once you've successfully installed Compass answer the question below: Did you download and install Compass? Answer: Yes Installed Compass.

Lab 1.1

Image
Welcome to your first lab in M201! In this lab you're going to install MongoDB Enterprise 3.4 and import the people dataset. While MongoDB Enterprise is available as part of the MongoDB Enterprise Advanced subscription it's permitted to be ran outside of production environments. In order to install MongoDB you're going to need to head over to our online documentation and follow the instructions on installing MongoDB. After you've successfully installed MongoDB you should start a standalone server. Once your sever is up and running you should be able to download the people.json handout and import it with mongoimport. Make sure to import the documents into the m201 database and the people collection. To confirm that you've successfully completed these steps run the following query on the m201 database from the mongo shell and paste it's output into the submission area below: > db.people.count({ "email" : {"$exists": 1} }) Answer

Question 7

Image
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 }) Whic h of  following is/are true? Answer: Index #1 would provide a sort to query #3. - True Index #2 properly uses the equality, sort, range rule for query #1. - False - If we were to build an index for query #1 using the equality, sort, range rule, then the index would be: { in_stock: 1, name: 1, price: 1 }. There would be a total of 4 index keys created across all of these documents and indexes. - False - As there would be 5 to