MongoDB 中的大集实现

发布于 2024-09-10 17:58:48 字数 500 浏览 2 评论 0原文

我在 MongoDB 中有一个数据集,其中涉及大量电子邮件,我需要能够将电子邮件添加到该集中,并能够检查某些电子邮件是否在该集中。我想处理这样的文档结构:

{'key': 'foo', 'emails':['[电子邮件受保护]','[电子邮件受保护] ', ...]}

并使用 $addToSet 和 $in。但问题是 Mongo 有 4MB 文档限制,如果有大量电子邮件,则可能不够。我可以将其信息键/电子邮件部分分开,但我担心这会使匹配(因为电子邮件现在不在一个地方)和插入(因为我需要检查唯一性)变慢。那么,最好的方法是什么?

I have a data set in MongoDB that involves a large set of emails and I need to be able to add emails to the set and being able to check if certain emails are in the set. I thought of doing with document structure like this:

{'key': 'foo', 'emails':['[email protected]','[email protected]', ...]}

and use $addToSet and $in. But the problem is that Mongo has 4MB document limit and if there's a lot of emails it could be not enough. I could split it info key/email parts but I'm worried it would make both matching (since emails aren't in one place now) and inserting (since I'd need to check for uniqueness) slower. So, what would be the best way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心不设防 2024-09-17 17:58:48

根据您将拥有多少组电子邮件,您可以将每组电子邮件设为一个集合,其中每个文档仅包含电子邮件地址。然后,您可以在电子邮件地址上创建唯一索引:

db.foo.ensureIndex({email:1},{unique:true})

Depending on how many sets of emails you're going to have you could make each set of emails a collection where each document consisted of only the email address. You could then create a unique index on the email address:

db.foo.ensureIndex({email:1},{unique:true})

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文