【发布时间】:2016-01-08 22:27:17
【问题描述】:
我的 Mongo 数据库中有 MemberSchema 和 FacebookSchema。
如果会员注册到我的网站,会员信息将存储在MemberSchema。
如果注册会员想要连接他的 facebook 帐户,他需要验证他的 facebook 帐户到我的网站。然后,他所有的脸书账号信息都会存储在FacebookSchema。
这是我当前的 Schema 配置:
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 属性连接。
但我已经考虑了另一种存储这些数据的方式,通过 Object 在 Schema 中键入。
var Member = mongoose.Schema({
webaccount : {
email : String,
password : String,
},
facebook : {
id : String,
token : String,
email : String,
name : String
}
});
您认为,在这种情况下,哪种方式可能更适合应用?
每种方法的优缺点是什么?
提前致谢。
【问题讨论】:
标签: node.js facebook mongodb mongoose schema