$filter and $addToSet for Array in Mongodb?

See this there are answers for this and for the updated one you asked.

I think something went wrong, and the one i was answering was deleted, but i found the same question duplicated by mistake, so i posted there the answer, hope all ok with your acount.

Both answers are complicated and slow, because you wanted in the answer to have data in keys, keys are better for the schema, and values to go to arrays or values in objects , not keys.