xxxxxxxxxx
db.collection.aggregate([{
$group : { _id: null, max: { $max : "$age" }}
}]);
xxxxxxxxxx
db.collection.find().sort({age:-1}).limit(1) // for MAX
db.collection.find().sort({age:+1}).limit(1) // for MIN
xxxxxxxxxx
var group = {$group:{_id:"$age", names:{$push:"$name"}, count:{$sum:1}}}
var sort = {$sort:{"_id":-1}}
var limit= {$limit:1}
db.selrac.aggregate([group, sort, limit])
xxxxxxxxxx
db.collection.find().sort("age",-1).limit(1) // for MAX
db.collection.find().sort("age", 1).limit(1) // for MIN
db.collection.find().sort("age", pymongo.DESCENDING).limit(1) // for MAX
db.collection.find().sort("age", pymongo.ASCENDING).limit(1) // for MIN