I am using mongodb in my rails app with odm mongoid
My questions are easy:
a) when associations between objects should be embedded or referenced?
b) how does this affect the application performance?
Thank you very much!
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Referenced relationships require multiple db lookups; embedded relationships don’t. But referenced relationships are easier to work with (especially if you are just starting out with your app and/or with mongo). I would recommend that you stay with referenced relationships until you have a better sense of the shape of your app and your data needs; at that point you can denormalize your data by switching some of those referenced relationships to embedded.
I would also recommend https://github.com/dzello/mongoid_alize to help with denormalization.