Skip to content

Instantly share code, notes, and snippets.

@Streemo
Created May 30, 2015 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Streemo/cbf5368ccea1a3bf061a to your computer and use it in GitHub Desktop.
Save Streemo/cbf5368ccea1a3bf061a to your computer and use it in GitHub Desktop.
do i need to delete the reference before reassingning a value to the key?
//all of this code is in a function.
var docs = Meals.aggregate(pipeline)
var oldData = Cache.regulars.data
var newData = {};
docs.forEach(function(doc){
var id = doc._id
var raw = _.omit(doc,'_id');
newData[id] = raw
var oldDoc = oldData[id]
if (oldDoc && (raw.score.total-oldDoc.score.total)){
self.changed('regulars',id,{score:raw.score})
} else {
self.added('regulars',id,raw);
}
})
delete Cache.regulars.data;
Cache.regulars.data = newData;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment