MongoDB:“避免在文档中使用无界数组”。
我在MongoDB中有此通知模式,用于向单个和/或所有经过验证的用户发送约350K用户录制的通知。
{
message: {type: String},
sender: {type: Schema.Types.ObjectId, ref: 'User'},
receivers: [{type: Schema.Types.ObjectId, ref: 'User'}],
readBy: [{
user: {type: mongoose.Schema.Types.ObjectId, ref: 'User'},
readAt: {type: Date, default: Date.now}
}]
}
问题是,接收器
和readby
字段不再很好地扩展(当我们仍然有数千个用户时,几乎没有开始,但现在是一场噩梦)和Mongodb Atlas Schema Advisor建议不要设计(最近将DB从Digitalocean转移到MongoDB Atlas)。
以下是Mongodb Atlas顾问仪表板的消息:
建议:避免在文档中使用无界数组
发现的问题:在扫描中检测到10,000多个条目的阵列
我检查了绩效顾问仪表板的参考链接,涉及如何修复它,但对我的用例并没有给我太多见解。
我想寻求有关您如何实施不同的建议/想法。
我当时正在看一种订阅基础方法,但是我还没有真正抓住它,我无法很好地缠绕它。
谢谢。
I have this notification schema in MongoDB for sending notifications to single and/or all verified user in a DB of ~350k user-records.
{
message: {type: String},
sender: {type: Schema.Types.ObjectId, ref: 'User'},
receivers: [{type: Schema.Types.ObjectId, ref: 'User'}],
readBy: [{
user: {type: mongoose.Schema.Types.ObjectId, ref: 'User'},
readAt: {type: Date, default: Date.now}
}]
}
Problem is, both receivers
and readBy
fields do not scale well anymore (started little when we still have a few thousands of users, but it's now a nightmare), and MongoDB Atlas schema advisor advised against the design (recently moved the DB from DigitalOcean to MongoDB Atlas).
Below are the messages from the advisor's dashboard of MongoDB Atlas:
Advice: Avoid using unbounded arrays in documents
Issues found: Arrays with over 10,000 entries detected in the collection(s) scanned
I checked the reference link from the performance advisor's dashboard on how to fix it, but did not give much insight to my use case.
I'd like to seek advice/ideas on how you'd implement yours differently.
I was looking at a subscription base method, but I haven't really get the grip of it, I couldn't wrap my head around it well enough.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论