medium10 pts · first answer countsdatabasesmongodb
findOneAndUpdate returns the old value
This code logs the stock before the decrement, not after. Why?
const doc = await products.findOneAndUpdate(
{ _id: id },
{ $inc: { stock: -1 } }
)
console.log(doc.stock)Discussion 0
Join free to post in the discussion.
Related questions
- Embed or reference in MongoDBBackend Developer
- Building SQL from user inputBackend Developer
- What atomicity guaranteesBackend Developer
- WHERE column = NULL finds nothingBackend Developer
- COUNT(*) versus COUNT(column)Backend Developer
- Column type for pricesBackend Developer
- Storing order times for two countriesBackend Developer
- Students and courses table designBackend Developer