I have the below DB like entries :
My insert query
db.collection.insert({company:\"C3\",model:\"M3\",price:55600,discount:9,resolution:\"1
You need to use the .aggregate() method for it to work.
db.collection.aggregate([
{ "$group": {
"_id": null,
"max": { "$max": "$price" },
"min": { "$min": "$price" }
}}
])
The _id
field is mandatory in the $group stage and to find the max/min values for price for the hole collection not for special group it needs to be set to null otherwise the query will only return max/min for each group