Я хочу обновить значение promotional
, если оно больше credit
. Я хочу установить его на 30
, иначе я хочу установить на 20
.
* 1007. * Документ
{
"_id" : "XX",
"promotional" : 200,
}
Код
let creditDeduct= 100
let accountId = 'xx'
this.adapter.collection.findAndModify(
_id = accountId,
[["_id", "asc"]],
{ "$inc": { $cond: { if: { $gte: [ '$promotional', creditDeduct ] }, then: 30, else: 20 }} },
{ "new": true, "upsert": true },
function(error, doc) {
if (doc) {
console.log(doc);
}
if(error){
console.log(error);
}
}
);
Ошибка
{ MongoError: Cannot increment with non-numeric argument: {$cond: { if: { $gte: [ "$promotional", 100 ] }, then: 30, else: 20 }}
at Connection.<anonymous> (/xx/xx/node_modules/mongodb/lib/core/connection/pool.js:466:61)
at Connection.emit (events.js:198:13)
at processMessage (/xx/xx/node_modules/mongodb/lib/core/connection/connection.js:364:10)
at Socket.<anonymous> (/xx/xx/node_modules/mongodb/lib/core/connection/connection.js:533:15)
at Socket.emit (events.js:198:13)
at addChunk (_stream_readable.js:288:12)
at readableAddChunk (_stream_readable.js:269:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17) ok: 0, errmsg: 'Cannot increment with non-numeric argument: {$cond: { if: { $gte: [ "$promotional", 100 ] }, then: 30, else: 20 }}', code: 14, codeName: 'TypeMismatch', name: 'MongoError', [Symbol(mongoErrorContextSymbol)]: {} }