我正在尝试创建两个猫鼬模式,一个用于用户,主要用于身份验证,另一个用于用户配置文件,其中它将具有用户的配置文件映像bio...etc
当使用猫鼬挂钩创建用户文档时,如何自动创建配置文件,以及如何在两个模式之间创建(一对一)关系?
发布于 2022-08-30 09:07:43
按照以下代码片段创建模型文件&根据您的需求更新params
User.model.js
let Schema = mongoose.Schema;
let Profile = new Schema({
image: {
type: String,
required: true
},
bio: {
type: String,
required: true
}
});
let User = new Schema({
email: {
type: String,
required: true
},
password: {
type: String,
required: true
}
profile: Profile,
}, {timestamp: true});
module.exports = mongoose.model('User', User);https://stackoverflow.com/questions/73538326
复制相似问题