I have a collection let's say called Persons which has the following information.
{
   name: "John Doe",
   gender: "m",
   phone: [ 123, 564, 123 ]
},
{
   name: "Elsa",
   gender: "f",
   phone: [ 456, 6789, 123 ]
},
{
   name: "Smith",
   gender: "m",
   phone: [ 55, 3244, 55]
}
What I want is to run an updateMany method query which goes through each one these objects and where ever in the array there are phone number duplication, it should remove those duplication.
As in if the phone was previously [ 123, 548, 123] I want it to be [ 123, 55 ]. I did some research on Stack overflow the implementations I found were people using aggregations or a forEach loop. Is there a better way to do it. Any help or directions would be highly appreciated.
I don't want an implementation with an aggregation or using a for loop.
So object in "John Doe" and "Elsa" can have the repeated phone number 123 But John Doe shouldn't have 123 repeated twice.
I have a collection with more then 1000 objects. Isn't there a way I could remove duplication from all objects.
Thank you.