0
我在我的Mongo數據庫中有MemberSchema
和FacebookSchema
。Mongoose - 多模式與一個模式內的對象存儲連接的文檔
如果會員註冊我的網站,會員信息將被存儲在MemberSchema
。
如果註冊會員想要連接他的facebook賬戶,他需要向我的網站驗證他的Facebook賬戶。然後,他的所有Facebook帳戶信息將存儲在FacebookSchema
。
這就是我目前的架構配置:
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' }
});
兩個模式是通過的MemberSchema
facebookAcount
財產相連。
但我已經考慮過在Schema中通過Object
類型存儲這些數據的另一種方法。
var Member = mongoose.Schema({
webaccount : {
email : String,
password : String,
},
facebook : {
id : String,
token : String,
email : String,
name : String
}
});
從你的意見,這可能是更好的方法來應用在這種情況下?
每種方法的優點和缺點是什麼?
在此先感謝。