show dbs
use test
db.products.insert( { "description": "motorcycle", "price" : 1000 })
To find all items in a collection
db.products.find()
db.products.find({description: /c/i }) db.products.find({description: 'motorcycle' })
Give us the model
name
$group {
_id: "$model"
Create a property maxValue
in the returned object:
$group {
maxValue:
Set it’s value to the the maximum of the memory
column:
{$max: "$memory"}
function aggProds(){
MongoClient.connect("mongodb://localhost:27017/meanpcdb", function(err, db) {
if(err) { return console.dir(err); }
var cursor = db.collection('products').aggregate([{
$group: {
_id:"$model",
"maxValue": {$max:"$memory"}}}]);
cursor.get(function(err, results) {
console.log(results);
});
return null;
});
}
gives:
[ { _id: 'iPhone 6 Plus', maxValue: 128 } ]
nn#+END_SRC
from data:
[{"category":"thumb drive",
"capacity":32,
"price":50,
"currency":"CAD",
"brand":"Kingston",
"model":"DataTraveler 101 G2",
"usb2":"true"
},
{"category": "phone",
"price":749,
"model":"iPhone 6 Plus",
"memory":16},
{"category": "phone",
"price":849,
"model":"iPhone 6 Plus",
"memory":64},
{"category": "phone",
"price":949,
"model":"iPhone 6 Plus",
"memory":128}]