大型 mongoDB 集上的嵌入与链接 (ruby)
嵌入式与链接
我正在寻找在新闻通讯文档中搜索连接电子邮件的最快方法。到目前为止,我已经将 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前 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.