Updated Mongoose Update Nested Array Element
I have the following Schema UserSchema: Schema = new Schema({ username: String, password: String, chat: [{ lastSeen: { type: Date, default: Date.now }, room: {
Solution 1:
I'm posting the solution in case someone needs it.
UserSchema.statics.lastSeen =
function lastSeen(username: string, roomId: number, date: Date) {
this.update({
username: username,
'chat.room': roomId
}, { $set: { 'chat.$.lastSeen': date }})
.exec();
};
Post a Comment for "Updated Mongoose Update Nested Array Element"