Hello,
I’m making a messages
collection on the client. I need to be able to watch it (on the client side) so that I know when a new message is added. Then I can show it to the user. Is there any way to do this?
Thanks!
Hello,
I’m making a messages
collection on the client. I need to be able to watch it (on the client side) so that I know when a new message is added. Then I can show it to the user. Is there any way to do this?
Thanks!
You don’t need to “watch” it per-se, just:
messages
collectionconst messagesArray = messages.find({}).fetch()
There are a couple of options.
If you simply use a mongo query into messages as the return from a helper in blaze, then that query will be reactive and will automatically update.
If you are using other tools, there is Tracker.autorun which will automatically re-run the function passed into it if anything in it changes state (including a collection being modified).
Finally there is http://docs.meteor.com/#/full/observe which works on both server and client. You can “observe” a collection causing callbacks to be fired as it mutates.
this is going on my QOTD board!
I think the observe method was what I was looking for.
Thanks for the help!