Friday 5 May 2017

Call document.save on maybe deprecated document

I'll planing to use mongoose for node.js. And I can't find solution for properly save the document after some async operations.

I think about, if during execution "getAsyncData", my founded document will update by another part of code, therefore my document will be not up-to-day. And if I perform save on it, I will lose that data which have been write to it by another part of code.

db.collection.findOne({}, function(err, document) {
   if (err) throw err;

   getAsyncData(function(err, data) { // founded document may change during perform this operation by another part of code
       if (err) throw err;

       document.data = data;
       document.save();
   });
});



via Eugene

No comments:

Post a Comment