I am storing unordered data in arrays in MongoDB and want to retrieve distinct sets.
For example, my data is:
{message_id: 1, participants: [ 'user1', 'user2'] }
{message_id: 2, participants: [ 'user2', 'user1'] }
{message_id: 3, participants: [ 'user3', 'user4'] }
{message_id: 4, participants: [ 'user4', 'user3'] }
And I want to return the arrays into distinct sets (with values in no specific order):
[ 'user1', 'user2' ]
[ 'user3', 'user4' ]
Is it possible to deduplicate unordered arrays like this? This is for a data migration task, so it doesn't have to be performant.