mongoose事务操作,参考官网

https://docs.mongodb.com/manual/reference/method/db.collection.bulkWrite/

await model.photo.bulkWrite([{
updateMany: {
"filter":{'customerIds.code': 'VICKY123456'} ,
"update": {'orderHistory': [ {"customerId":'VICKY123456','createdOn':new Date()}]}
}
}])

已实验成功

原文地址:https://www.cnblogs.com/qiyc/p/9476538.html