New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
findByIdAndUpdate not updating #1060
Comments
I cannot reproduce on v3.0.2. Which version of Mongoose/MongoDB/Node are you using? What are the before/after values you are updating? |
I found out why it didn't work. My schema didn't contain the name field. I added the field and it worked. The reason I didn't discover this earlier was because apparently you can create new documents without the schema being complete. |
I met the same problem. How do you fix it? |
Long ago. Make sure that your schema has all the fields you are trying to find and modify. Other parts of Mongoose may still work without the field in the schema. Maybe say some more about your problem and @aheckmann can help you out :) |
Agreed with @hallas . Make sure your schema contains all the fields you're trying to |
i was having the same issue. i fixed with a await before User.findByIdAndUpdate |
User.findByIdAndUpdate(req.body._id, {
$set: {
name: req.body.name
}
}, { upsert: true },
function (err, user) {
return res.json(err == null ? user : err);
}
);
This code does not work. It simply returns the document without the updated name field. This means that the _id is correct, but what's not working? I tried alot of different combinations.
The text was updated successfully, but these errors were encountered: