Closed Glavin001 closed 9 years ago
count
and total
(and other stats) in a stats
key:max
and min
{
timestamp_hour: ISODate("2013-10-10T23:00:00.000Z"),
type: “memory_used”,
values: [
[ 999999, 999999, …, 1000000 ],
[ 2000000, 2000000, …, 1000000 ],
…,
[ 1600000, 1200000, …, 1100000 ],
[ 1300000, 1400000, …, 1500000 ]
],
stats: [
[ count, total, min, max], // Minute 0
[ count, total, min, max], // Minute 1
// ....
],
count: 0,
total: 0,
min: 0,
max: 0
}
$max
and $min
I notice that the min
field is not getting set, because BSON comparison order puts null
as less than a number. Instead of storing it in the order of [count, total, min, max]
, store it as [count, total, max, min]
where min
is empty by default, not null
, such that on insert/default it is [0,0,0]
for [count,total,max,min]
and the $min
update modifier will detect that the 3rd index is missing and initialize it with the minimum value.
See http://stackoverflow.com/a/21924176/2578205