Context
In a MongoDB database, I have a collection with mail documents inside. Each document has receiver and sender fields.
Goal
I want to query for one mail from each sender. In other words, I do not want two or more mail from the same sender.
Example
I have three documents:
{
_id: 1,
sender: John,
receiver: Kate
}
{
_id: 2,
sender: John,
receiver: Kate
}
{
_id: 3,
sender: Mike,
receiver: Kate
}
After the query, I should end up with: (the second mail from John is not included)
{
_id: 1,
sender: John,
receiver: Kate
}
{
_id: 3,
sender: Mike,
receiver: Kate
}
Please help! Thanks.