I'm using the method below to update all the fields in the "Producers" document.
exports.updateProducers = async (req, res) => {
let obj = new Producers(req.body);
await Producers.findOneAndUpdate({ "user.nome": "Naomi"}, obj, {upsert: true, new: true}, function (err) {
(err ? res.status(400).send(err) : res.status(200).json(obj));
});
}
This method works and normally updates all the "Producers" fields, however, I have a reference to the "User" document, done like this:
user: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User',
required: true
},
In "Users", I have the "name" field. How can I add editing on users as well?
I'm currently getting this message:
MongoError: Performing an update on the path '_id' would modify the immutable field '_id'
I appreciate if anyone can help me analyze what I'm doing wrong?