我即将建立我的 node .js/express/mongoose/passport应用程序,我正在考虑用户和帐户的正确schema design.
There will be users loging in from twitter and facebook as well as from native accounts. At a later stage I want a user to connect both twitter and facebook with my application (and maybe even more external accounts).
我想不出解决那种情况的好办法.以下是我正在考虑的选项:
1.拥有个人资料模型和账户模型.配置文件文档代表唯一的用户,而帐户提供用户名和密码(内部帐户)或来自身份验证提供程序(外部帐户)的身份验证数据.配置文件必须至少有一个nested帐户文档.
var ExtAccountSchema = new Schema({
type: String, // eg. twitter, facebook, native
uid: String
});
var IntAccountSchema = new Schema({
username: String,
password: String
});
var ProfileSchema = new Schema({
firstname: String,
lastname: String,
email: String,
accounts: [Account] // Pushing all the accounts in there
});
我不喜欢的是,不同的帐户数据导致的帐户文档不太一致,而且当我的用户登录时,我很难找到正确的帐户(在嵌套文档中搜索UID和帐户类型)
2.所有数据都在a single model
var ProfileSchema = new Schema({
firstname: String,
lastname: String,
email: String,
twitter-uid: String,
facebook-uid: String
password: String
});
这太难看了找到正确的帐户数据可能更容易/更快,但维护起来并不好.
有更好的解决方案吗?Is there a best practice?