So I have a model of Chat.
const Schema = mongoose.Schema;
const chatSchema = mongoose.Schema({
    id              : {type: String, required: true, unique: true},
    email1          : String,
    email2          : String,
    avasrc1         : String,
    avasrc2         : String,
    lastMessage     : String,
    lastMsgTime     : String,
    messages        : [{email: String, name: String, avasrc: String, msg: String, msgTime: String}]
});
And in server I want to change avatar sources to if email match email. So I tried...
await Chat.update({email1: email}, {$set: {avasrc1: avatar}}, {multi: true})
await Chat.update({email2: email}, {$set: {avasrc2: avatar}}, {multi: true})
await Chat.update({messages: {$elemMatch:{email: email}}},{"$set": {"messages.$.avasrc": avatar}}, {multi: true})
In a result it works only for first one. I need to change:
- All avasrc1 to avatar if email1 = email
- All avasrc2 to avatar if email2 = email
- All messages.avasrc in whole array to if messages.email = email
 
    