在MongoDB中的$ project中重命名年份字段

时间:2015-09-16 13:14:01

标签: mongodb aggregation-framework

我正在尝试在项目阶段重命名我的ID字段,但是我有一条错误消息。 $ match和$ sort阶段工作正常。以下是详细信息:

db.complaints.aggregate([
    {$match:{$text:{$search:"\"loan\""}}},
    {$group:{"_id":{Year:{$substr: ["$received", 0, 4]}}, "loan":{$sum:1}}},
    {$sort:{_id:-1}},
    {$project:{_id:0, "Year":"_id.Year", "loan":1}}
])

这是我的架构:

> db.complaints.findOne()
{
    "_id" : ObjectId("55e5990d991312e2c9b266e3"),
    "complaintID" : 1388734,
    "product" : "mortgage",
    "subProduct" : "conventional adjustable mortgage (arm)",
    "issue" : "loan servicing, payments, escrow account",
    "subIssue" : "",
    "state" : "va",
    "ZIP" : 22204,
    "submitted" : "web",
    "received" : "2015-05-22",
    "sent" : "2015-05-22",
    "company" : "green tree servicing, llc",
    "response" : "closed with explanation",
    "timely" : "yes",
    "disputed" : ""
}

0 个答案:

没有答案