【发布时间】:2013-03-02 18:37:26
【问题描述】:
我在 pymongo 中编写了以下聚合查询,以从 "high" 列中获取最高值,从 low 列中获取最低值。
db.bseadjprice.aggregate([
{
"$match":
{
"date" : {"$in":['2012-03-15 00:00:00.000', '2012-03-16 00:00:00.000']},
"scripcode":"533159"
}
},
{
"$group" :
{
"_id" : "$scripcode",
"high":{"$max":"$high"},
"low":{"$min":"$low"}
}
}
])
由于这些值在刺痛我得到不正确的值。
有没有办法解决这个问题,比如输入“int($low)”并得到正确答案?
谢谢。
【问题讨论】:
-
除非您可以将集合转换为在这些字段中包含整数值,否则您将无法获得正确的结果,因为 aggregate() - $project:{ihigh: 中没有类型转换运算符{$add:["$high",0]}} 返回错误。如果你不能转换集合中的数据,你可以使用 mapReduce() 代替,见documentation
标签: python mongodb pymongo aggregation-framework