I'm fairly new to MongoDB queries and I'm struggling to get an idea if its possible and if yes how to solve this problem.
My DB objects from this collection consist of different fields and a list of objects. inside these objects there are regular string fields.
I now realised that there are duplicates (wrong logic in my code) that have to be deleted now. but I cant search and delete about 10'000 DB entries so I thought there must be a query for that.
For example: in this example, object one and two are duplicates because string_1 and string_2 are in both objects the same. So one of the two first objects has to be deleted
{
"string" : "",
"string" : "",
"string" : "",
"list of objects" : [
{
"string_1" : "2",
"string_2" : "2",
"string_3" : "1",
},
{
"string_1" : "2",
"string_2" : "2",
"string_3" : "4",
},
{
"string_1" : "3",
"string_2" : "5",
"string_3" : "3",
},
]
}
Desired outcome would be: (it keeps the first off the duplicates (where string_1 and string_2 are equal between the objects))
{
"string" : "",
"string" : "",
"string" : "",
"list of objects" : [
{
"string_1" : "2",
"string_2" : "2",
"string_3" : "1",
},
{
"string_1" : "3",
"string_2" : "5",
"string_3" : "3",
},
]
}
Any help is appreciated
string_1andstring_2identical to another item? or if any string, for example,string_3is identical in two items, then one of them should be deleted?