【发布时间】:2020-01-10 10:15:06
【问题描述】:
我有一个 mongo 集合,其中包含字段 id、mobile 和 name 数组。
以下是我的收藏示例,
{
"_id": 1,
"mobile": "555-555-5555",
"name": { "first" : ObjectId("1122334455") }
}
{
"_id": 2,
"mobile": "222-222-2222",
"name": { "first" : ObjectId("5544332211") }
}
{
"_id": 3,
"mobile": "111-111-1111",
"name": { "first" : ObjectId("1122334455")}
}
我想将数组name 中的first 字段从ObjectId 重命名为literal
所以我的输出会是这样的,
{
"_id": 1,
"mobile": "555-555-5555",
"name": { "first" : "Tom" }
}
{
"_id": 2,
"mobile": "222-222-2222",
"name": { "first" : "abigail" }
}
{
"_id": 3,
"mobile": "111-111-1111",
"name": { "first" : "Tom"}
}
【问题讨论】:
-
Tom、abigail是从哪里来的? -
它是一个要替换的字符串,对于 ObjectId("1122334455") - "Tom"
标签: mongodb aggregation-framework aggregation