chat = {
messages: [ { body:"asdf", timestamp: 234256243 },
{ body:"asdf", timestamp: 234256241 },
{ body:"asdf", timestamp: 544256244 },
};
Suppose I had a collection of chat rooms. I want to find the rooms with the latest messages. How do I sort by the timestamp of messages?
chat.find().sort...by messages array timestamp descending.
It’s an embedded sort.
There is not presently support for sorting embedded arrays in MongoDB. You’ll need to do the sorting on the clientside with the programming language of your choice.