Skip to content

Instantly share code, notes, and snippets.

@christianhager
Created June 22, 2010 09:19
Show Gist options
  • Save christianhager/448227 to your computer and use it in GitHub Desktop.
Save christianhager/448227 to your computer and use it in GitHub Desktop.
#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 ('someemail@email.com')
#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 => 'someemail@email.com')
unless email
email = Email.new(:email => 'someemail@email.com', :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