In my program, I have used an an mongoose query to find the particular document after found, need to do certain logic and update that instance after the logic portion done in my node js.
Example:
1. const user = await User.findById(userId)
2. #... logic to be implement by using above user
3. #... more logic
4. user.update({$set: { verified: true })
In line 4, I want to use the same instance of the document to update, I don't know how to implement it. Help me to resolve this.
CodePudding user response:
You can update fields on the user by setting them directly, ie: user.verified = true;
.
Once you are done updating the user you can execute await user.save();