Answer the question
In order to leave comments, you need to log in
How to update value in array of mongoDB object?
Hello. Help with a question on monga.
From the node I make a request to update the data, but I get a strange situation.
We have such an object.
_id: 61c4f31d0c7a0a29c238d5c8
firstName: "NAME",
middleName: "",
lastName: "",
phoneNumbers:
[
{phoneNumber: "111111", phoneStatus: false, defaultPhone: true, _id: 61c4f31d0c7a0a29c238d5c9},
{phoneNumber: "2222", phoneStatus: false, defaultPhone: true, _id: 61c4f31d0c7a0a29cdff4d5c9},
],
avaSrc: ""
[
{phoneNumber: "111111", phoneStatus: false, defaultPhone: true, _id: 61c4f31d0c7a0a29c238d5c9},
{phoneStatus: true, defaultPhone: true, _id: 61c4f31d0c7a0a29cdff4d5c9},
],
await UserModel.findOneAndUpdate({
phoneNumbers: { $elemMatch: { phoneNumber: "2222"} },
}, {$set: { phoneNumbers: { phoneStatus: true}
});
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question