MongoDB shell obtains the maximum and minimum values. mongodbshell

Source: Internet
Author: User

MongoDB shell obtains the maximum and minimum values. mongodbshell

MongoDB does not find a dedicated method to calculate the maximum value, but it can be replaced by sorting and getting the first one.

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 command to find the maximum value of 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 very simple. You only need to 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 }


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.