我的保存是:
tx = new Transaction transaction
tx.save (err) ->
console.log err
cb err
这样可以节省。
Transaction.update transaction, {upsert: true}, (err, num, raw) ->
console.log err
console.log num
console.log raw
但是,我的更新不会更新文档。此外,对于,它返回noerr
和0 num
。这是与"mongoose": "~3.8.0"
该update
函数的第一个参数是查询,以匹配一个或多个文档(参考)。
我希望该调用Transaction.update
仅包括文档的_id
,而不是整个对象。第二个参数是整个文档或使用更新运算符的对象。
您可能想要:
Transaction.update _id : transaction._id, transaction, upsert: true,
(err, num, raw)->
或者,也许您想使用记录在案的更新操作符之一来设置该事务的特定属性。
Transaction.update _id : transaction._id, $set : { amount : 500 } ,
upsert : true, (err, num, raw) ->
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句