Skip to content Skip to sidebar Skip to footer

Got Duplicated Data When Subscribe Multiple Times

I am using MongoDB aggregation in meteor. I got duplicated data when subscribe multiple times. (The data in database are static, which means they are same all the time.) // Server

Solution 1:

The problem is that you are using a random id each time in the call to added so the client always thinks all of the documents are unique. You need to devise a consistent id string generator. Using an answer to this question, you could imagine building a set of functions like these:

hashCode = function (s) {
  return s.split('').reduce(function (a, b) {
    a = ((a << 5) - a) + b.charCodeAt(0);return a & a;
  }, 0);
};

objectToHash = function (obj) {
  returnString(hashCode(JSON.stringify(obj)));
};

So if you wanted a unique document for each combination of code and hour you could do this:

var id = objectToHash(r._id);
this.added('totalNumber', id, {...});

Post a Comment for "Got Duplicated Data When Subscribe Multiple Times"