I am unwinding an array using MongoDB aggregation framework and the array has duplicates and I need to ignore those duplicates while doing a grouping further.
How can I achieve that?
you can use $addToSet to do this:
db.users.aggregate([ { $unwind: '$data' }, { $group: { _id: '$_id', data: { $addToSet: '$data' } } } ]);
It's hard to give you more specific answer without seeing your actual query.
2.1m questions
2.1m answers
60 comments
56.8k users