Created
June 22, 2010 09:19
-
-
Save christianhager/448227 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment