我正尝试将收藏夹中的所有文档退还给其中
Fields.fields[x].subFields.field_1 = A
和
Fields.fields[x].subFields.field_2 = B.
如果子字段不存在,我可以匹配它
例如给了文件
{
"_id" : "4",
"Fields" : { "_id" : "1",
"Type" : "Person",
"fields" : [{ "_id" : "1",
"Field_1" : "a",
"Field_2" : "b",
"Field_3" : "c"
}]
}
}
我可以使用
进行匹配{
"Fields.fields" : { "$elemMatch" : { "Field_1" : "a",
"Field_2" : "b"
}
}
}
但是,如果我将这些字段再往下推,我将不知道如何匹配它。
{ "_id" : "10",
"Fields" : { "_id" : "1", "Type" : "Person",
"fields" : [{ "_id" : "1",
"subFields" : { "Field_1" : "a",
"Field_2" : "b",
"Field_3" : "c" }
}
}]
}
}
我没有运气尝试
{
"Fields.fields.subFields" : { "$elemMatch" : { "Field_1" : "a",
"Field_2" : "b"
}
}
}
也尝试过
{
"Fields.fields" : { "$elemMatch" : { subFields: {"Field_1" : "a",
"Field_2" : "b"
}
}
}
}
这可能吗?如果是这样,我该怎么做。我对文档格式没有太多控制,因此不想遍历它。