{
"_id" : "5b606326502f3f055862cfee",
"Brand" : 5,
"IsPublished" : false,
"RowItems" : [
{
"RowType" : 2,
"Text" : "AAAA11111",
"GroupId" : "22e5293c-2dc2-4159-b290-3c8988a27744",
"LevelIndex" : 1,
"ItemIndex" : 0,
"RowItems" : [
{
"RowType" : 3,
"Text" : "A1",
"TagId" : "5762a47cf5f79234582e5dea",
"GroupId" : "e660cdce-409c-4f51-b4a5-efc9aafc90bd",
"LevelIndex" : 2,
"ItemIndex" : 0,
"RowItems" : []
},
{
"RowType" : 3,
"Text" : "A2",
"TagId" : "5762a476f5f79234582e5d7e",
"GroupId" : "a0206caa-5793-44ba-aabd-19123e4e50f0",
"LevelIndex" : 2,
"ItemIndex" : 1,
"RowItems" : []
},
{
"RowType" : 3,
"Text" : "A3",
"TagId" : "578bda4700380f09e02c4df6",
"GroupId" : "c1760707-09d9-426f-8331-d4d08a1cd916",
"LevelIndex" : 2,
"ItemIndex" : 2,
"RowItems" : [
{
"RowType" : 2,
"Text" : "BBBB",
"GroupId" : "7ee73eb0-52d2-4157-88d8-859bfcb76b17",
"LevelIndex" : 3,
"ItemIndex" : 0,
"RowItems" : [
{
"RowType" : 3,
"Text" : "B1",
"TagId" : "5762a4e0f5f79234582e604f",
"GroupId" : "15f8bf28-8eb4-4d2a-82bf-e4c86e9b78b9",
"LevelIndex" : 4,
"ItemIndex" : 0,
"RowItems" : []
},
{
"RowType" : 3,
"Text" : "B2",
"TagId" : "5762a480f5f79234582e5e12",
"GroupId" : "c299f240-d0dd-402e-a690-3c49e3b6d2b7",
"LevelIndex" : 4,
"ItemIndex" : 1,
"RowItems" : []
}
]
},
{
"RowType" : 2,
"Text" : "CCCC",
"GroupId" : "b1f18c28-5cc5-4e41-81b6-6ab688c6a243",
"LevelIndex" : 3,
"ItemIndex" : 1,
"RowItems" : [
{
"RowType" : 3,
"Text" : "C1",
"TagId" : "578bda4700380f09e02c4df6",
"GroupId" : "dc392245-410d-443a-894f-2fbb6c50ec1d",
"LevelIndex" : 4,
"ItemIndex" : 0,
"RowItems" : []
},
{
"RowType" : 3,
"Text" : "C2",
"TagId" : "5762a480f5f79234582e5e14",
"GroupId" : "1f3ed72b-daf9-48c3-a299-4e7ea7d1f347",
"LevelIndex" : 4,
"ItemIndex" : 1,
"RowItems" : []
}
]
}
]
}
]
},
{
"RowType" : 2,
"Text" : "BBBB",
"GroupId" : "1ec01e29-adb7-412f-be92-1a5482ec8311",
"LevelIndex" : 1,
"ItemIndex" : 1,
"RowItems" : [
{
"RowType" : 3,
"Text" : "Marketing aftersales",
"TagId" : "5762a4e0f5f79234582e604f",
"GroupId" : "69358bfb-c32e-4910-93b8-6eeabe36daf4",
"LevelIndex" : 2,
"ItemIndex" : 0,
"RowItems" : []
},
{
"RowType" : 3,
"Text" : "Modern Retailing",
"TagId" : "5762a480f5f79234582e5e28",
"GroupId" : "bad86185-0436-40fb-bff1-50602bd0ea5a",
"LevelIndex" : 2,
"ItemIndex" : 1,
"RowItems" : [
{
"RowType" : 2,
"Text" : "CCCC",
"GroupId" : "da51ea8f-733e-4c19-a546-f90220e28dce",
"LevelIndex" : 3,
"ItemIndex" : 0,
"RowItems" : [
{
"RowType" : 3,
"Text" : "Modern Retailing",
"TagId" : "5762a480f5f79234582e5e98",
"GroupId" : "760e84d7-6a7c-450a-b669-110fe45c2238",
"LevelIndex" : 4,
"ItemIndex" : 0,
"RowItems" : []
},
{
"RowType" : 3,
"Text" : "Modern Retailing case studies",
"TagId" : "578bda4700380f09e02c4df6",
"GroupId" : "5a77c1c5-facf-4088-b4a6-65f4014e8b81",
"LevelIndex" : 4,
"ItemIndex" : 1,
"RowItems" : []
}
]
}
]
}
]
}
],
"CreatedDate" : ISODate("2018-07-31T10:24:54.000Z"),
"CreatedBy" : "AM002GY",
"UpdatedDate" : ISODate("2018-08-24T10:06:04.189Z"),
"UpdatedBy" : "AM002GY"
}
我在一个集合中嵌套了 RowItems。我需要根据标签 id 找到任何 rowitem。
如果我通过 TagId ="5762a480f5f79234582e5e28" 那么我需要
{
"RowType" : 3,
"Text" : "Modern Retailing",
"TagId" : "5762a480f5f79234582e5e28",
"GroupId" : "bad86185-0436-40fb-bff1-50602bd0ea5a",
"LevelIndex" : 2,
"ItemIndex" : 1,
"RowItems" : [
{
"RowType" : 2,
"Text" : "CCCC",
"GroupId" : "da51ea8f-733e-4c19-a546-f90220e28dce",
"LevelIndex" : 3,
"ItemIndex" : 0,
"RowItems" : [
{
"RowType" : 3,
"Text" : "Modern Retailing",
"TagId" : "5762a480f5f79234582e5e98",
"GroupId" : "760e84d7-6a7c-450a-b669-110fe45c2238",
"LevelIndex" : 4,
"ItemIndex" : 0,
"RowItems" : []
},
{
"RowType" : 3,
"Text" : "Modern Retailing case studies",
"TagId" : "578bda4700380f09e02c4df6",
"GroupId" : "5a77c1c5-facf-4088-b4a6-65f4014e8b81",
"LevelIndex" : 4,
"ItemIndex" : 1,
"RowItems" : []
}
]
}
欢迎使用 Stack Overflow @ravi-shekhar。作为对未来的提示,如果你展示你尝试过的东西,这是一种很好的形式,人们会更倾向于以这种方式指导你。
这个答案可能有帮助:如何使用 elemMatch 来匹配嵌套数组
您可以查看使用 $elemMatch
困难可能是您的嵌套结构......
如果你在你的第一级搜索,RowItems
你会做这样的查询:
{
"RowItems": {
$elemMatch: {
GroupId: "a0206caa-5793-44ba-aabd-19123e4e50f0"
}
}
}
我认为因为它是嵌套的,你可以这样做:
{
"RowItems": {
$elemMatch: {
"RowItems": {
$elemMatch: {
TagId: "5762a47cf5f79234582e5dea"
}
}
}
}
}
我没有试过这段代码,所以它可能不起作用,但应该有助于你思考这个问题
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句