Answer the question
In order to leave comments, you need to log in
How to query like select ... for update in MongoDB?
How to query like select ... for update in MongoDB?
I am using the mongodb driver in NodeJS.
I want to use something like this: I do
n’t see examples in the documentation, it’s hard to understand.
let user = await db.users.findOne({user: 1}).toArray()
if(user.balance <= 100) {
user.balance = 100
}
user.save()
Answer the question
In order to leave comments, you need to log in
findOneAndUpdate()
You can also do the same as you indicated an example from the documentation.
In your example, you enter the user into a variable, then change the field in it, after which you save, what is not clear?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question