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() {
ItemCollection.find().observe({
added: function(item) {
// Alert code
}
});
});
And I found that not only alerts are displayed when a new item is added to the database on the server side ( which I suppose is normal :) ) but alerts are also displayed for each previously added item when I refresh the page. I suppose Meteor fetch all the data from the Mongo database on startup (to populate the local Minimongo DB) and then fires 'added' event for each item added in the local database.
But is this the normal behavior ? How can I receive only items that are "truly" added in the database on the server ?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…