【发布时间】:2017-06-06 01:35:39
【问题描述】:
我正在处理一个 MongoDB 查询
db.BH.group({
"key": {
"AccountId": true,
},
"initial": {
"count": 0
},
"reduce": function(obj, prev) {
if (true != null) if (true instanceof Array) prev.count += true.length;
else prev.count++;
},
"cond":
{"$or":[{"Url":{"$regex":"(google)"}},{"Url":{"$regex":"(facebook)"}}]}
});
查询在 MongoDB Shell(Robomongo) 中运行良好。
我已经为 python 编写了相同的查询。
db.BH.group({
"key": {
"AccountId": True,
},
"initial": {
"count": 0
},
"reduce": "function(obj, prev) {"
"if (true != null) if (true instanceof Array) prev.count += true.length;"
"else prev.count++;"
"}",
"cond": {"$or":[{"Url":{"$regex":"(google)"}},{"Url":{"$regex":"(facebook)"}}]}
})
但是查询出错了。
TypeError: group() takes at least 5 arguments (2 given)
我尝试通过以下网站(URL)中给出的方法解决错误
http://blog.pythonisito.com/2012/05/aggregation-in-mongodb-part-1.html
但同样的错误仍然存在。
【问题讨论】:
标签: python mongodb mongodb-query pymongo