I am not sure whether “distinct” is the right word for this.
I have a simple messaging system in mongo with “sender”,”receiver”,”content”.
The problem I have is in the inbox page: say for example I have 3 messages from John and 4 from Jack, I would like to show in my inbox only the last message sent by each of those people.
I have searched online and I thought this http://www.mongodb.org/display/DOCS/Aggregation#Aggregation-Distinct would be the right thing but, it doesn’t seem to work or atlest I can’t get it to work… meh..
Ciao Enrico,
I didn’t really get your question, so I’ll try to explain how distinct works:
If then you run:
What you’ll get will be:
And I don’t think that will be of any use to you. Instead try sorting by date sent and limiting the results to one: