【发布时间】:2015-04-14 16:16:49
【问题描述】:
我在patients colletion 中有数十亿条记录,
我不知道如何用管道过滤它。
或者这是对 mongoDB 的限制,我们无法在大型集合上与管道聚合?
我已经添加了allowDiskUse=True 选项,但它也不起作用。
如何获得管道过滤后的结果?
我怎样才能简单地将过滤后的结果存储到另一个集合中?谢谢
示例代码(我使用pymongo,所以以下是Python语法)
import datetime
pipeline = [
{"$project": {"birthday":1, "id":1}
},
{
"$match": { "birthday":{"$gte":datetime.datetime(1987, 1, 1, 0, 0)} }
},{"$group": ~~~
}
]
res =db.patients.aggregate(pipeline,allowDiskUse=True)
异常信息
OperationFailure: command SON([('aggregate', u'patients'), ('pipeline', [{'$match': {'birthday': {'$gte': datetime.datetime(1987, 1, 1, 0, 0)}}}]), ('allowDiskUse', True)]) on namespace tw_insurance_security_development.$cmd failed: exception: aggregation result exceeds maximum document size (16MB)
如何
【问题讨论】:
-
看起来您在聚合返回游标之前使用的是 MongoDB 版本。升级到 >= 2.6。