We had the following request in Node.JS
mongo.connect('mongodb://XXX: XXX@ds054XXX.mlab.com :54289/XXXdb', function (err, db) { var collection = db.collection('chatmessages') var stream = collection.find().sort({ _id: -1 }).limit(20).stream(); stream.on('data', function (chat) { socket.emit('user message', chat.content, chat.dateCreated); }); });
As you can see, the query is a collection of the last 20 entries entered. But then from this result we would like to resort again to 1 in _id, so in the list we will have ID 55 - 75, for example (order). So the last one is always down.
How can we achieve this again?
source share