Given a list of documents like:
[
{
_id: 1,
field1: "test",
field2: "value2",
fields: [
"field1",
"field2"
]
},
{
_id: 2,
field1: "value1",
field2: "test",
fields: [
"field1",
"field2"
]
},
{
_id: 3,
field1: "test",
field2: "value2",
fields: [
"field2"
]
},
{
_id: 4,
field1: "value1",
field2: "value2",
fields: [
"field1"
]
},
{
_id: 5,
field1: "test",
field2: "test",
fields: []
}
]
I want to retrieve all documents that have any of the specified fields in the array, with a value “test”. For instance, in document with _id: 1
, field2
is a value of fields
array, and field2
has test
as value. In contrast, document with _id: 5
has keys field1
and field2
with test value, but none of this fields is present in fields array. So, given the previous list of documents, only documents with _id: 1
and _id: 2
should be returned.