MongoDB:“避免在文档中使用无界数组”。

发布于 2025-02-09 02:54:59 字数 937 浏览 0 评论 0原文

我在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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文