使用填充获取未读邮件计数-mongodb

时间:2019-06-13 08:05:21

标签: mongodb mongodb-query

嗨,我正在尝试获取未读邮件计数的朋友列表。我有一个名为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' }]
});

我能够用最后一条消息完成用户的所有聊天,现在我也希望未读消息计数。

0 个答案:

没有答案