MongoDB has not found a dedicated method to find the maximum value, but can be sorted and take the first one instead.
The following collection data is as follows:
{"_id": ObjectId ("54c39358acace71b1bd20a70"), "Epoch_min": Numberlong (1422030840), "Usage_ratio": 0.035140007734298706} {"_id": ObjectId ("54c39358acace71b1bd20a71"), "Epoch_min": Numberlong (1422030900), "Usage_ Ratio ": 0.025494230911135674} {" _id ": ObjectId (" 54c39358acace71b1bd20a72 ")," Epoch_min ": Numberlong (1422030960)," Usage_ratio ": 0.015415809117257595}
The maximum command to find out the Usage_ratio is:
Mongodbcluster3:primary> Db.cpu_data.find (). Sort ({"Usage_ratio": -1}). Limit (1) {"_id": ObjectId (" 54c39abbacace71b1bd599ac ")," Epoch_min ": Numberlong (1422039660)," Usage_ratio ": 0.5287633538246155}
The minimum value is simple, just replace-1 with 1:
Mongodbcluster3:primary> Db.cpu_data.find (). Sort ({"Epoch_min": 1}). Limit (1) {"_id": ObjectId (" 54c39358acace71b1bd20824 ")," Epoch_min ": Numberlong (1422028800)," Usage_ratio ": 0.053253963589668274}
MongoDB shell gets maximum and minimum values