cursor.observe({added}) behavior in Meteor

前端 未结 1 1818
深忆病人
深忆病人 2021-01-05 00:24

I\'m trying to display an alert to the user when data is added to the database. So I wrote (on the client side) :

Meteor.autosubscribe(function() {
  ItemCol         


        
相关标签:
1条回答
  • 2021-01-05 00:46

    You are observing a cursor for the client side database and that database may not finish syncing until after the page is done loading, so the behavior makes sense. You may want to look into explicitly subscribing to a collection as discussed in the answer to this question.

    If your data had a created_at field then you could observe items created after the page loads.

      ItemCollection.find({created_at : {$gt: some_current_time}}).observe({
        added: function(item) {
          // Alert code
        }
      });
    
    0 讨论(0)
提交回复
热议问题