I am trying to find out how I can make a mongodb aggregation to delete duplicate documents according to a specific parameter. When I say duplicates I don't mean that the whole document is the same. For example I have the following documents:
{
'event': 123,
'element': 'element1'
},
{
'event': 456
'element': 'element2'
},
{
'event': 789
'element': 'element1'
},
{
'event': 111
'element': 'element3'
}
I would like to make an aggregation that if I specify the field "element" will return me all documents without element duplication. I know that the typical question is, ok but if there are two documents with 'element1' Which one do I want? the answer is that I dont mind if it returns me one or the other, this is why I dont know if this is possible
return example:
{
'event': 123,
'element': 'element1'
},
{
'event': 456
'element': 'element2'
},
{
'event': 111
'element': 'element3'
}
It is also OK if it returns me:
{
'event': 456
'element': 'element2'
},
{
'event': 789
'element': 'element1'
},
{
'event': 111
'element': 'element3'
}