我在设置适当的会话模式时遇到问题,该模式存储对话和/或消息的读/未读标志。我希望当前登录的用户能够看到有多少会话中有新消息。目前,我的模式(使用imple-模式)看起来有点像这样:流星/ MongoDB对话模式
Schema = {};
Schema.ConversationMessageRead = new SimpleSchema(
{
"userId": {
type: String
},
"createdAt": {
type: Date
}
}
);
Schema.ConversationMessage = new SimpleSchema(
{
"userId": {
type: String
},
"message": {
type: String,
optional: true
},
"read": {
type: [Schema.ConversationMessageRead],
optional: true
},
"createdAt": {
type: Date
}
}
);
Schema.Conversation = new SimpleSchema(
{
"participants": {
type: [String],
optional: false
},
"messages": {
type: [Schema.ConversationMessage],
optional: true
},
"deleted": {
type: Boolean,
optional: false,
defaultValue: false
},
"createdAt": {
type: Date
}
}
);
Conversations = new Mongo.Collection("conversations");
Conversations.attachSchema(Schema.Conversation);
我这背后的想法是更新所有消息的子文档read
财产与当他们打开了一个对话的当前用户ID。然后我很快发现你现在不能update multiple subdocuments。
我愿意改变对话系统的管理方式,如果有人有一个想法,以适当的方式来实现这一点。还有一件事要记住,我想保持它的反应,这意味着我不得不查询这个集合,而不使用聚合函数。要做到这一点
其实,我最初是按照你在最后一段中提到的方式构建系统的。尽管我很难查询数据。我可能会重新访问它。 – SeanWM