Can I return a boolean variable as per the conditions in a mongoose query?
Example, while getting all notification of a user, I want to show if a notification is seen by the user or not.
I have this schema:
const notificationSchema = mongoose.Schema({
userid: { type: mongoose.Schema.Types.ObjectId, ref:'User', require: true, unique: false },
time: Number,
type: Number,
seenBy: {type: [String], default: []} // can have very large number of values (user IDs)
}, {__v: false});
Now while getting the notifications array I want to get an extra field which seen
which is true if a specific user exists in respective seenBy[] array of the field.
such that I get the response object like
1 new notification
[{userid: <someid>, time: ... <other fields> ..., seen: false}]
Thank you
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…