I am using the following query to update the documents in mongodb but it throws me the error The dollar ($) prefixed field '$subtract' in 'abc.$subtract' is not valid for storage.
const bulkUpdate = arrs.map(arr => {
const { val = 0 } = arr
return {
updateMany: {
filter: {
date: 20201010
},
update: {
$set: {
abc: {
$subtract: [val, { $add: [{ $ifNull: ['$a1', 0] }, { $ifNull: ['$b1', 0] } ] }]
}
},
},
},
}
})
if (bulkUpdate.length > 0) {
return mongoConnection.pool
.db('test')
.collection('testTable')
.bulkWrite(bulkUpdate)
}
Thanks is advance