标签云

微信群

扫码加入我们

WeChat QR Code

I have a problem when update the mongodb database using $cond and condition is not work.This is my code..Book.update({_id: {$in: keys}},{$cond: [{$gte: ["$item",1]},{$inc:{item: -1,count: 1}},{$set: {status: "01"},$inc:{count:1}}]},{multi: true},function(err, rtn) {if (err) throw err;console.log('book borrowed',rtn);Book.find({_id: {$in: keys}}, (err, book) => {if (err) throw err;for (var y in book) {record.books.push({book_id: book[y]._id,range: book[y].book_range,name: book[y].book_name,author: book[y].book_author,barcode: book[y].barcode});}record.save((err2, rtn) => {if (err2) throw err2;res.json({status: true,msg: "Book Borrowing process is succefully complete!!"});});});});


$cond is return one value. So need to add new update query with item:'0' and set status "01"

2019年06月19日09分35秒