大型 mongoDB 集上的嵌入与链接 (ruby)

发布于 2024-09-07 05:23:10 字数 1184 浏览 7 评论 0原文

嵌入式与链接

我正在寻找在新闻通讯文档中搜索连接电子邮件的最快方法。到目前为止,我已经将 MongoMapper 与一个用于新闻通讯的文档和另一个用于电子邮件的文档一起使用。对于+100k 电子邮件来说,这变得非常慢。

我在想也许将电子邮件嵌入新闻通讯中的数组中会更快 因为我真的只对电子邮件感兴趣 ('[email protected] ') 并且没有任何围绕它的逻辑。

1) 是否可以在一个文档中嵌入多达 100k-500k 封电子邮件? 2)Mongoid 对此更好/更快吗?

如果电子邮件尚未在集合中,我会通过询问来添加它

email = newsletter.emails.first(:email => '[email protected]')
unless email
    email = Email.new(:email => '[email protected]', :newsletter_id => self.id)
    email.save
end

,我认为这就是一切开始受到伤害的地方。

这是它们的连接方式 班级通讯 包括 MongoMapper::Document 许多:电子邮件 ... end

Class Email
   include MongoMapper::Document
   key :email, String
   key :newsletter_id, ObjectId
   belongs_to :newsletter
end

希望对此有任何帮助:)

Embedded vs link

I'm looking for the fastest way to search a Newsletter document for a connected Email. So far I have used MongoMapper with one document for Newsletter and another for Email. This is getting really slow with +100k Emails.

I was thinking maybe its faster to embed the emails in an array inside Newsletter
since I'm really only interested in the email ('[email protected]')
and not any logic around it.

1) Is it possible at all to embed as much as 100k-500k emails in one document?
2) Is Mongoid better/faster for this?

I'm adding the email if it is not already in the collection by asking

email = newsletter.emails.first(:email => '[email protected]')
unless email
    email = Email.new(:email => '[email protected]', :newsletter_id => self.id)
    email.save
end

And I think this is where it all starts to hurt.

Here is how they are connected
Class Newsletter
include MongoMapper::Document
many :emails
...
end

Class Email
   include MongoMapper::Document
   key :email, String
   key :newsletter_id, ObjectId
   belongs_to :newsletter
end

would love for any help on this :)

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

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

发布评论

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

评论(1

余厌 2024-09-14 05:23:10

目前 MongoDB 的最大文档大小为 16mb,MongoMapper 或 Mongoid 对此没有影响。

请参阅 http://www.mongodb.org/display/DOCS/Documents

嵌入文档应不过,如果您可以在限制范围内容纳所有电子邮件,那么速度会快得多,这可能会很紧张。

如果存储整个电子邮件太多,为什么不只存储一个数组或只是将电子邮件地址嵌入新闻通讯中并引用完整电子邮件。

然后,您可以获得所需的速度优势,并保持电子邮件在时事通讯之外也可访问。

There is a maximum document size of 16mb currently for MongoDB, MongoMapper or Mongoid will make no difference to this.

see http://www.mongodb.org/display/DOCS/Documents

Embedded documents should be considerably quicker though, if you can fit all the emails within the limit could be a squeeze.

If storing the whole email is to much, why not just store either an array or just embedded the emails address withing the newsletter with a reference to the full email.

You can then get the speed advantage you want, and keep the emails accessible outside of the newsletter.

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