【发布时间】:2014-08-11 02:50:12
【问题描述】:
我正在尝试使用 nodejS 在 mongodb 中执行 findAndModify,这是我的代码:
var nextBill = function (db, success, log) {
var collection = db.collection('autoincrements');
log.debug('autoIncrementRepository', 'nextBill');
var result = collection.findAndModify({
query: { _id: 'auto' },
update: { $inc: { bill: 1 } },
new: true
});
success(result.bill);
};
编辑:
尝试回调
collection.findAndModify({
query: { _id: 'auto' },
update: { $inc: { bill: 1 } },
new: true
}, function (e, result) {
success(result.budget);
});
但是给我错误需要删除或更新..但我正在这样做..
【问题讨论】:
-
您使用的是哪个驱动程序? MongoDB节点原生驱动需要回调,mongoose、mongoose等也需要回调。
-
本机驱动程序,但使用回调我得到同样的错误:。我将使用我的实际代码编辑我的 awnser。
标签: javascript node.js mongodb mongodb-query