I have to save the different profiles of a user from various social media.for example user may have 1 facebook and 2 twitter profile. if i save the each profile it is inserted as a new document in different collections like facebook and twitter is a collections and how would i relate this document to another. I used dot notation in mongodb. if i relate the facebook and twitter profile of a same user means it is easy to fetch the record.How would i design the schema ? and also how would i avoid duplication
? Is any possible to use the facebook id twitter id as unique? I am new to mongoDB
. How would i join the documents from different collections
This is a ruby implementation, but hoping your able to translate the schema logic into your 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 the collections like so:
db.twitter_profiles.ensureIndex({user_id: 1 }, {unique: true})
db.facebook_profiles.ensureIndex({user_id: 1}, {unique: true})
You can use whatever field you want to enforce uniqueness at the user level.
Hope that helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.