Question: ************************ Mongo DB ******************************** Populate a vehicles collection using the following command (make sure that no documents exist in the collection before running the command).
************************ Mongo DB ********************************
Populate a vehicles collection using the following command (make sure that no documents exist in the collection before running the command).
db.vehicles.insertMany( [
{ model: "Accord",
make: "Honda",
type: "Sedan",
stock: [ { store: "Fraser", qty: 20 }, { store: "Maple", qty: 25 }, { store: "Moody", qty: 20 } ]
},
{ model: "Camry",
make: "Toyota",
type: "Sedan",
stock: [ { store: "Moody", qty: 30 }, { store: "North Shore", qty: 40 }, { store: "Rocky", qty: 45 } ]
},
{ model: "Civic",
make: "Honda",
type: "Sedan",
stock: [ { store: "Fraser", qty: 20 }, { store: "North Shore", qty: 30 }, { store: "Rocky", qty: 35 }, { store: "Valley", qty: 30 } ]
},
{ model: "Rav4",
make: "Toyota",
type: "SUV",
stock: [ { store: "Fraser", qty: 40 }, { store: "Moody", qty: 30 } ]
},
{ model: "Edge",
make: "Ford",
type: "SUV",
stock: [ { store: "Fraser", qty: 15 }, { store: "Moody", qty: 15 }, { store: "Rocky", qty: 25 }, { store: "Valley", qty: 20 } ]
},
{ model: "Ridgeline",
make: "Honda",
type: "Truck",
stock: [ { store: "Maple", qty: 35 }, { store: "Rocky", qty: 20 }, { store: "Valley", qty: 15 } ]
},
{ model: "F-150",
make: "Ford",
type: "Truck",
stock: [ { store: "Fraser", qty: 30 }, { store: "North Shore", qty: 35 } ]
}
] );
The stock array stores the quantity (qty) of a particular car model at a specific store. Assume that the qty is always greater than 0.
Question:
1. Find the SUV or Truck vehicles that are available at more than two stores. Display the model and make fields, as well as the total qty of all available stores.
2.Find each store that has at least 45 Honda vehicles (all types applicable). Display the store name and the total qty of all Honda vehicles at the store and sort the result in descending order of the total qty. The result is given below for your reference (the field name and order must be the same).

3. Find the model(s) that have the lowest total qty at all the stores. The result is given below for your reference (the field name and order must be the same).

\{ store: 'Maple', total_qty: 60}, { store: 'Rocky', total_qty: 55 , \{ store: 'Valley', total_qty: 45} [ \{ models: [ 'Accord', 'F-150' ], total_qty: 65} ]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
