I´m trying to update my database schema in its user topic . Its schema would look like this:
nickname: [Object],
email: [Object],
password: [Object],
image: [Object],
googleFlag: [Object],
groupOfChats: [Array],
role: [Object],
messages: [Array],
userState: [Object],
friends: [Array]
Where the item to modify would be the groupOfChats that is an array that contains several objects and on the objects there is an item ‘memberId’ which is a array of string ,being this last one the one i want to access to modify:
groupOfChats: [
{
idGroup: { type: String, required: true },
nameGroup: { type: String, required: true },
membersId: [{ type: String, required: false }],
groupCreatorId: { type: String, required: true },
messages: [{ type: String, required: false }],
groupImage: { type: String, required: false },
},
],
Trying to access that membersId item in a specific group i just tried to set this, but isn´t working:
let friendsAddedIdOnly =["des","pa","cito"];
let userChatGroupUpdate = User.updateOne(
{
_id: payload.idUserCreatorGroup,
"groupOfChats.idGroup": payload.groupId,
},
{ $push: { "membersId.$[]": friendsAddedIdOnly} },
{ new: true }
);
(await userChatGroupUpdate).save();
a view of my mongo database would be like this: