versionKey Issue when using save()

10 views
Skip to first unread message

Brian Manda

unread,
Jan 9, 2018, 6:06:45 AM1/9/18
to mongodb-user
Hey guys

Am currently trying to figure out why my save command is not updating my versionkey. If any one has any ideas or links to something to help please help. Since this is happening it causes the following issues:

 1. When more than one user works on a document(e.g. cms that allows a user to create custom HTML pages), the information from the first person is
 
     deleted since the second person has not refreshed their browser which results in the users over writing each others changes.
            2. No error handler is present which does not inform users if there are changes or that their version is behind.

Code snippet :

      if (pageBody) {
       
var book= new Book(pageBody);
        _
.extend(book, pageBody); // Am not too sure if the extend function here is working as it should

       
Book.findById(book._id, function(err, model) {
         
if (err) {
            cb
(err);
         
} else if (model) {
            model
.save(function(err, item) {
              console
.log('--------------------------------------------------------------------');
              console
.log(item);// The logs show the current info without the __v changing from 0
             
if (err) {
                cb
(err);
             
} else {
                cb
();
             
}
           
});
         
}
       
});
     
} else {
        cb
();
     
}  
 


Reply all
Reply to author
Forward
0 new messages