I want to update an array field of a mongodb document, pushing a new value into the array, and keeping only the recent 100 values, and do it as bulkWrite operation
According to official docs we can do
db.students.updateOne(
{ _id: 1 },
{
$push: {
scores: {
$each: [ 80, 78, 86 ],
$slice: -5
}
}
}
)
for single update operation, however when I try to do it using bulkWrite it gives syntax error (unexpected token ':' after $slice.
updateOne: {
filter: { name: coin.name }
update: {
$push: {
price_history: {
$each: [coin.current_price_inr],
$slice: -100
}
}
}