【发布时间】:2017-08-22 07:00:03
【问题描述】:
我尝试在 mongoengine 中使用聚合,但没有得到任何结果。初始代码:
result = Review.objects.aggregate([{'$match': {'status': 'Remind'}}])
但我得到了错误:
command SON([('aggregate', u'review'), ('pipeline', [[{'$match': {'status': 'remind'}}]]), ('cursor', {})]) on namespace db_name.$cmd failed: exception: pipeline element 0 is not an object
在参考了各种links之后,我更新了我的代码:
pipeline = [{ "$match": {'status': 'Remind' } }]
results = list(Review.objects.aggregate(*pipeline))
print 'result='+str(results)
现在,我没有收到任何异常或错误,但结果仍然为空
result=[]
这是我的示例 mongodb 数据:
{
"_id" : ObjectId("599aaf826bc80b178a00ef1"),
"timestamp" : "on Mar 19, 2017",
"profile" : "Aditya Roy",
"status" : "Remind",
"created_on" : ISODate("2017-08-21T15:31:38.052Z")
}
{
"_id" : ObjectId("599aaf826bc80b178a00ef2"),
"timestamp" : "on Mar 16, 2017",
"profile" : "Shivam Singh",
"status" : "Remind",
"created_on" : ISODate("2017-08-21T15:31:38.778Z")
}
{
"_id" : ObjectId("599aaf836bc80b178a00ef3"),
"timestamp" : "on Mar 13, 2017",
"profile" : "Gautam Sharma",
"status" : "Closed"
"created_on" : ISODate("2017-08-21T15:31:39.526Z")
}
【问题讨论】:
标签: mongodb python-2.7 mongoengine