I have a scenario where I will only fetch one document and then reduce several array properties in that document so each contains one or more array elements.
Example:
{
array_property1:
[
{
language_code: "EN-US"
...
},
{
language_code: "EN-UK"
...
}
],
...
}
I am able to reduce the number of array elements using $elemMatch
, however it will only result in one array element. Is there any other method to achieve an array reduce for one or more objects instead of just one when using find command?
The reason for this is because I have heard that using find instead of aggregation in this scenario would yield a better performance and would also be much easier to maintain because it is only one document I am retriving using an objectID.