4

I am trying to understand when I might use this.flush() in a Meteor application.

The docs state the following

Call inside publish function. Sends all the pending set, unset, and complete messages to the client.

If my publish function is something like this

Meteor.publish('myCollection', function(myid){
    return MyCollection.find({_id: myid});
});

would I use this.flush()?

What kind of case would one use this.flush() in?

Thanks S

Steeve Cannon
  • 3,682
  • 3
  • 36
  • 49

1 Answers1

1

Not needed in that use case, because Meteor.publish automatically handles the details of how to turn Mongo cursors into the appropriate set and unset commands for each subscribed client.

If you write a custom publish that manages its own set and unset, you can use flush to push all pending changes down to the client. You'll find an example of that technique here: How does the messages-count example in Meteor docs work?

Community
  • 1
  • 1
debergalis
  • 11,870
  • 2
  • 49
  • 43