【发布时间】:2016-06-10 07:25:00
【问题描述】:
我正在使用 pymongo 的 map_reduce 框架从 mongodb 中提取一些数据。这是我的数据的样子:
{
"_id" : ObjectId("566f570e3816dc2fe631db4f"),
"property_id" : 5594.0000000000000000,
"reservation_id" : "2544430.1",
"updated" : ISODate("2015-12-15T02:04:33.000Z"),
"offer_list" : {
"68799" : {
"pitched" : "no",
"accepted" : "no"
},
"68801" : {
"pitched" : "no",
"accepted" : "no"
}
},
"status" : "awarded",
"comments" : "",
"agent_id" : 1.0000000000000000,
"created" : ISODate("2015-12-14T23:55:52.000Z")
}
我需要在某个日期后使用 pymongo 获取每个代理的所有记录计数。
映射器函数如下所示:
mapper = Code("""function(){
if(this.created>start_date){
emit(this.agent_id, 1);
})
其中 start_date 是从 python 代码传入的变量。
通过阅读文档,我认为应该设置范围,但我找不到任何有关如何执行此操作的文档。我对javascript一无所知。有人可以帮忙吗?
提前致谢!
【问题讨论】:
-
你为什么需要这个
map_reduce?你能显示预期的结果吗? -
预期输出为 {agent_id:1, count:12},表示自 start_date 以来代理有 12 条记录
标签: mongodb scope mapreduce pymongo