I have a collection with messages looking like this:
{
"_id" : ObjectId("593929aa070f5e2f8ce60a1c"),
"by" : "User1",
"to" : "testAccount",
"userImage" : "0cddd4ieiLdtrwerrbabad9a4353330725712fe3b1348239",
"time" : NumberLong("1496918441854"),
"text" : "Hello there",
"type" : 0
}
This collection represents the messages which user can send. And now I want to display a list of chats for each user, like whatsapp. For this I want to get only the last message of this chat (to or by = "User1"). What's the best way to do this? Something with group?
Or is there a better way instead of getting just the last one? Because I think it's better in performance than getting more of it.