I have following documents:
doc1: {
'array': [
{'field': 'ABC', 'enabled': 'false'},
{'field': 'BCD', 'enabled': 'true'},
{'field': 'DEF', 'enabled': 'false'},
{'field': 'XYZ', 'enabled': 'true'},
]
}
doc2: {
'array': [
{'field': 'ABC', 'enabled': 'true'},
{'field': 'BCD', 'enabled': 'true'},
{'field': 'DEF', 'enabled': 'false'},
{'field': 'XYZ', 'enabled': 'true'},
]
}
I'm performing search by particular field. I want to get all documents that have this field enabled, and there are no other fields enabled before this (in the list).
For ex.:
search for field: BCD, enabled: true - should return only first document (because in second document ABC is enabled too).
search for XYZ, enabled: true - should not return any documents at all, because there are other fields enabled on top of this list.
I was trying to do smth with $elemMatch, but I don't know if it's possible to apply filter on top of element that elemMatch has matched.
Any suggestions?