Answer the question
In order to leave comments, you need to log in
MongoDB/Mongoose how to remove property from returned object?
I'm doing an update UserModel.findOneAndUpdate(_id, data)
. The whole object with new data is returned back.
How to say base. so that it does not include a certain property of the object?
For example, here I can control it: UserModel.findOne({_id}, {property: 0})
Can I do the same here?
Answer the question
In order to leave comments, you need to log in
you can pass an object with fields that you need or don't need further to the select method
UserModel.findOneAndUpdate(_id, data)
.select({property: 0})
UserModel.findOneAndUpdate(_id, data)
.select({property: 0})
.exec(function(err, user) {
//...
});
UserModel.findOneAndUpdate(_id, data)
.select({property: 0})
.then(user => {
//...
})
.catch(err => {
//...
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question