We have a aggregate query with merge similar to below with update operation for $set. Expectation is that this update will be run through aggregation. But looking through logs, it is sometimes run as single update operation for all matching records with IDHACK in queryplan. This is causing unnecessary delay to pipeline execution.
[{
$merge: {
into: 'target',
on: '_id',
whenMatched: [{
$set: {
fieldA: '$$new.fieldA',
fieldB: '$$new.fieldB'
}
}],
whenNotMatched: 'discard'
}
}]