I need to count the number of duplicate IDs that occur across all documents in a collection. However, this very simple aggregation is complicated by the fact that the IDs in question may appear in multiple fields in the input document.
Suppose I have input documents like the one below:
I'd like to transform this to a document that looks like:
From this point, it is straightforward to unwind and group on c to get to the desired result.
The above transformation is similar to what would be achieved using the $setUnion operator, but here I do not want to filter out duplicate values.
Therefore, this request is for an operator similar to $setUnion but which does not filter out duplicate values.