$inc not working with MongoDB and Node.js (Mongoose)

357 views Asked by At

I'm trying to figure out why my code breaks after the update using $inc.

.then(function(food){

console.log("MYFOOD", food);
console.log("QUAN", food.quantity); 
  return [Food.update({_id: foodId},
  {$inc: {quantity: -1}} 
  ), food];
})
.spread(function(update, food){
  console.log("QUAN2", food.quantity);
})

food is an object that has the key quantity in it and a value as a positive number) If I misspell the word quantity, it'll go to the next section and show QUAN2 as undefined, but when everything looks correct and quantity is spelled right it breaks and won't even go to the .spread section. The problem seems to be coming from the update

this works when I hard code it though: return [Food.update({_id: food._id}, {$set: {quantity: "2"}} ), food] })

0

There are 0 answers