String imageSource = myactivity.getResources().getString(R.string.changUrla);
我想要做的是,用文档替换id字段。
{
"id": "1",
"label" : "alex",
"children" : [
{
"id" : "rJqS8aW-W"
},
{
"id" : "SkF8UaW-W"
}
],
}
{
"label" : "felix",
"id" : "rJqS8aW-W",
"children" : [
{
"id" : "S1gcBUT---"
},
{
"id" : "r1ltUUpZbb"
}
]
}
{
"label" : "tom",
"id" : "SkF8UaW-W",
"children" : [
{
"id" : "S1gcBUT---"
},
{
"id" : "r1ltUUpZbb"
}
]
}
....
为了能够做到这一点,我写道;
{
"id": "1",
"label" : "alex",
"children" : [
{
"id" : "rJqS8aW-W"
},
{
"id" : "SkF8UaW-W"
}
],
details: [
{
"label" : "felix",
"id" : "rJqS8aW-W",
"children" : [
{
"id" : "S1gcBUT---"
},
{
"id" : "r1ltUUpZbb"
}
]
},
{
"label" : "tom",
"id" : "SkF8UaW-W",
"children" : [
{
"id" : "S1gcBUT---"
},
{
"id" : "r1ltUUpZbb"
}
]
}
]
}
...
但它并没有像我预期的那样回归。我们不能对数组使用db.collection.aggregate([
{$lookup: {from: "collection" , localField: "children.id", foreignField: "id", as: "details"}}
])
吗?我的意思是我想根据数组中的字段进行搜索。
编辑:
一些修改,例如,
$lookup
或
db.collection.aggregate([
{$lookup: {from: "collection" , localField: "$children.id", foreignField: "id", as: "details"}}
])
也会引发错误。
我该怎么办? db.collection.aggregate([
{$lookup: {from: "collection" , localField: "children.$.id", foreignField: "id", as: "details"}}
])
ID字段是flat
而不是children
?