嗨,我正在尝试获取未读邮件计数的朋友列表。我有一个名为user的集合。
var userSchema = new Schema({
name: {type: String, default: null},
chat: [{type: Schema.Types.ObjectId, ref: 'chat'}]
});
我将用户完成的所有聊天存储在聊天中。聊天集合如下:-
var chatSchema = new Schema({
participants: [{type: Schema.Types.ObjectId, ref: 'user' }],
lastMessage: {type: Schema.Types.ObjectId, ref: 'message'},
isGroup: {type: Boolean,default: false},
groupName: {type: String,default: ""},
groupImage: {type: String,default: ""},
groupDetail: {type: String,default: ""},
blockedUser: [{type: Schema.Types.ObjectId, ref: 'user' }],
admin: {type: Schema.Types.ObjectId, ref: 'user' }
});
消息架构如下:-
var messageSchema = new Schema({
participants: [{type: Schema.Types.ObjectId, ref: 'user' }],
messageBy: {type: Schema.Types.ObjectId, ref: 'user' },
chatId: {type: Schema.Types.ObjectId, ref: 'chat' },
message: {type: String,default: "" },
createdOn: {type: Date, default: Date.now()},
readBy: [{type: Schema.Types.ObjectId, ref: 'user' }]
});
我能够用最后一条消息完成用户的所有聊天,现在我也希望未读消息计数。