Reputation: 6168
I'm building association as follow
person embeds one address
address references one country
address references one province
country embeds many provinces
Is above association is good? I'm too much confused how to build them. I don't know exact use of mongodb and mongoid for building association.
Main concern of mine is when to use embedded and when to use references associations?
Upvotes: 1
Views: 1781
Reputation: 17629
Schema design in MongoDB depends on how you will query the data and how you will update the data. There is no general hard rule to determine if an associations should be embedded or referenced. I suggest you have a look at this excellent article.
Concerning your suggested schema you could also make the country an attribute/field on a province document and do less normalization than you would in a relational database. It all depends on how you access your documents.
collection provinces:
{
name : 'Alabama'
country : 'United States'
}
Upvotes: 5