如何使用 max 和 mongoDB 中的 where 条件在集合中查找输出
How to find output in a collection using max and where condition in mongoDB
我这里有一个名为 data 的 table 我有一个名为 _id、timeStamp、value 的数据。我需要使用特定日期的 where 条件获取最大值
db.data.aggregate([ { "$group": { "_id": null, "MaximumValue": { "$max": "$value" }}}]);
您可以在运行之前使用$match
$group
:
db.collection.aggregate([
{ $match: { timeStamp: 1584948532188.0 } },
{ $group: { _id: null, maxVal: { $max: "$value" } } }
])
然后 $max
仅应用于过滤后的文档集
我这里有一个名为 data 的 table 我有一个名为 _id、timeStamp、value 的数据。我需要使用特定日期的 where 条件获取最大值
db.data.aggregate([ { "$group": { "_id": null, "MaximumValue": { "$max": "$value" }}}]);
您可以在运行之前使用$match
$group
:
db.collection.aggregate([
{ $match: { timeStamp: 1584948532188.0 } },
{ $group: { _id: null, maxVal: { $max: "$value" } } }
])
然后 $max
仅应用于过滤后的文档集