Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

09 NodeChatroom - sorting the stream #6

Open
swinston100 opened this issue Apr 24, 2016 · 0 comments
Open

09 NodeChatroom - sorting the stream #6

swinston100 opened this issue Apr 24, 2016 · 0 comments

Comments

@swinston100
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant