具有嵌套数组的示例数据:
[
{
"rows": [["123", "234", "345"], ["345", "456", "567"]]
},
{
"rows": [["111", "222", "333"], ["444", "555", "345"]]
},
]
给定一个特定值(例如345
),我希望将找到的值及其第一个数组索引(例如row_i
)和第二个数组索引(例如col_i
)聚合到结果中:
[
{"value": "345", "row_i": 0, "col_i": 2},
{"value": "345", "row_i": 1, "col_i": 0},
{"value": "345", "row_i": 1, "col_i": 2},
]
我知道如何使用$elemMatch
(Example 1)聚合整个文档,但这不包括行/列索引.
我try 使用$unwind
,但只能使用嵌套对象,而不能使用数组(Example 2).我有一个限制,那就是我根本不能更改数据 struct .