I have MemberSchema
and FacebookSchema
in my Mongo Database.
If the member registers to my website, the member info will be stored in MemberSchema
.
If the registered member want to connect with his facebook account, he needs to authenticate his facebook account to my website. Then, all his facebook account information will be stored in FacebookSchema
.
That's my current Schema configuration:
var Member = new Schema({
email: String,
password: String,
memberType: { type: String , default: 'webaccount' },
facebookAccount: { type: Schema.Types.ObjectId, ref: 'facebook_accounts' }
});
var FacebookAccount = new Schema({
fbId: String,
email: { type : String , lowercase : true},
name: String,
memberType: { type: String , default: 'facebook' }
});
The two schemas are connected via facebookAcount
property of MemberSchema
.
But I've considered another way of storing these data by Object
type in Schema.
var Member = mongoose.Schema({
webaccount : {
email : String,
password : String,
},
facebook : {
id : String,
token : String,
email : String,
name : String
}
});
From you opinion, which might be the better way to apply in this situation?
What are the advantages and disadvantages of each approach?
Thanks in advance.