I need to use both $set and $push within one update call. I have done it as mentioned in $push and $set in same MongoDB update
Now my code is
await this.collection.updateOne(
{ id },
[
{
$set: {
...changes,
"metadata.updated": new Date(),
"metadata.updatedBy": { id: updatedBy }
}
},
{
$push: {
history: {
user: { id: updatedBy },
type: HistoryType.TIME_ENTRY_UPDATED,
date: new Date(),
args: changes
}
}
}
]
);
But it is throwing MongoError: Unrecognized pipeline stage name: '$push'
Whats wrong with my code.
My mongodb server version - 4.2.9 node package client version - ^2.2.36