【发布时间】:2014-06-15 18:23:50
【问题描述】:
我正在研究 Mongodb,我正在使用 Mongoose,我想创建一个非常动态的注册过程。我使用 Passport 管理了注册的第一步,一切正常,我创建了用户并且它存在于数据库中。现在我的注册过程将继续,用户必须选择一个“角色”:你是什么样的用户?有 2 个选项:“基本”和“高级”。 Basic 仅有 3 个属性,advanced 有 3 个基本属性以及其他几个属性。
我需要扩展 userSchema 或添加基于该角色的新字段,但一周后它还不起作用,我尝试了许多 NPM,例如:mongoose-relationship 或猫鼬模式扩展。
这基本上就是我所拥有的:
userSchema = new Schema({
id : Number,
email : { type: String, required: true },
role : { type: String, required: true },
profile : { ... } // Profile fields are different for each role.
});
// profile 1
basicSchema = new Schema({
info1 : { type: String, required: true },
info2 : { type: String, required: true },
info3 : { type: String, required: true }
});
// profile 2
advancedSchema = new Schema({
info1 : { type: String, required: true },
info2 : { type: String, required: true },
info3 : { type: String, required: true },
info4 : { type: String, required: true },
info5 : { type: String, required: true },
info6 : { type: String, required: true }
});
用户已经存在并且他在一个屏幕上,他需要选择一个角色并填充所选的配置文件。
关于我使用 nodejs 和 expressjs 的信息。
希望你能帮上忙。谢谢。
【问题讨论】:
-
用户的个人资料对象是否需要存在于用户对象之外?或者您总是将它与 User 对象一起获取?
标签: database node.js express mongoose