java - Mongo Db schema -


i have save different profiles of user various social media.for example user may have 1 facebook , 2 twitter profile. if save each profile inserted new document in different collections facebook , twitter collections , how relate document another. used dot notation in mongodb. if relate facebook , twitter profile of same user means easy fetch record.how design schema ? , how avoid duplication? possible use facebook id twitter id unique? new mongodb. how join documents different collections

this ruby implementation, hoping able translate schema logic java code.

 class user     has_one :facebook_profile     has_one :twitter_profile  end   class twitterprofile     belongs_to :user   end   class facebookprofile    belongs_to :user  end 

you can enforce unique indexes on collections so:

 db.twitter_profiles.ensureindex({user_id: 1 }, {unique: true})  db.facebook_profiles.ensureindex({user_id: 1}, {unique: true}) 

you can use whatever field want enforce uniqueness @ user level.

hope helps.


Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -