Shamoon Shamoon - 5 months ago 66
Node.js Question

Mongoose save not working for some odd reason from a findOne

Gig.findOne({
_id: data.gig
}).populate(populate).exec(function(err, gig) {
gig.lastChatTime = Date.now();
gig.lastChatBy = params.by;
gig.meta.chats += 1;
return gig.save(function(err) {
return console.log(err);
});
});


When I do the
.save
, it doesn't save, but it also doesn't error. What gives?

Answer

try something like this

Gig.findOne({
  _id: data.gig
}).populate(populate).exec(function(err, gig) {
   if(gig){

      Gig.update({_id: gig._id},
                 {
                   lastChatTime : Date.now(),
                   lastChatBy : params.by,
                   meta.chats : meta.chats+ 1
                 },
                 {
                   runValidators: true
                 },function(err){
                 if(err){
                   throw err;
                 }
        );
  }
});
Comments