09 NodeChatroom - sorting the stream
Opened this issue · 0 comments
swinston100 commented
Hi thanks for the tutorials/examples. Really learning a lot. I have a query about the Node Chatroom in Ex 9.
Upon a new connection we take the mongo database and return 10 values
As it stands I tested and this returns the first 10 values.
var stream = collection.find().sort().limit(10).stream();
To return the most recent we need:
var stream = collection.find().sort({ $natural: -1 }).limit(10).stream();
This returns the newest value first (ie top of the list). Ideally we want the newest value at the bottom so we'd need to reverse the stream. I read that stream takes a transform function but I can't figure it out, I am very new to this world of developing - any help would be appreciated in this next step! Thanks!