Basically I need to increase an counter in an document and get the new value, but this has to work atomically.
Current I'm using the mand:
.updateOne({_id: ObjectId('5ed7f23789bcd51e9c6a82e0')}, {$inc: {nextTicket: 1}})
But I can't find how to immediately get the new incremented value.
Basically I need to increase an counter in an document and get the new value, but this has to work atomically.
Current I'm using the mand:
.updateOne({_id: ObjectId('5ed7f23789bcd51e9c6a82e0')}, {$inc: {nextTicket: 1}})
But I can't find how to immediately get the new incremented value.
Share Improve this question edited Apr 26, 2024 at 9:05 Jonas 129k103 gold badges328 silver badges405 bronze badges asked Aug 11, 2020 at 12:19 Ivo FritschIvo Fritsch 1351 silver badge7 bronze badges1 Answer
Reset to default 6updateOne
does not return the document / the documents fields.
What you want to do is use findOneAndUpdate. now this still returns the "old" document so you want to specify returnOriginal: false
.findOneAndUpdate({_id: ObjectId('5ed7f23789bcd51e9c6a82e0')}, {$inc: {nextTicket: 1}}, {returnOriginal: false})
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744990220a4604857.html
评论列表(0条)