【发布时间】:2014-07-24 15:25:43
【问题描述】:
我有一些如下形式的 Mongodb 文档:
{
"auditedId" : "53d0f648e4b064e8d746b31c",
"modifications" : [
{
"auditRecordId" : ObjectId("53d0f648e4b064e8d746b31d"),
"modified" : "2014-07-22 18:33:05"
},
{
"auditRecordId" : ObjectId("53d0f648e4b064e8d746b31e"),
"modified" : "2014-07-24 14:15:27"
},
{
"auditRecordId" : ObjectId("53d0f648e4b064e8d746b31f"),
"modified" : "2014-07-24 12:04:24"
}
]
}
对于这些文档中的每一个,我都想找到与最新修改相对应的“auditRecordId”值。在给定的示例中,我想检索
"auditRecordId" : ObjectId("53d0f648e4b064e8d746b31e")
或者,甚至更好:
{
"auditRecordId" : ObjectId("53d0f648e4b064e8d746b31e"),
"modified" : "2014-07-24 14:15:27"
}
有什么方法可以在不编写 map-reduce 函数的情况下做到这一点?
【问题讨论】:
标签: mongodb mapreduce aggregation-framework