如何在一个命令中使用猫鼬检索配置文件和用户架构?
如何将用户和个人资料放在一起?
这是User
模式的定义方式:
const UserSchema = new Schema({
email: { type: String, required: true },
name: { type: String, required: true },
password: { type: String },
picture: { type: String },
});
和配置文件模式:
const ProfileSchema = new Schema({
user: { type: Schema.Types.ObjectId, ref: 'User' },
setting1: { type: String, enum: ['YES', 'NO', 'UNKNOWN'], default: 'UNKNOWN' },
setting2: { type: String, enum: ['YES', 'NO', 'UNKNOWN'], default: 'UNKNOWN' },
setting3: { type: String, enum: ['YES', 'NO', 'UNKNOWN'], default: 'UNKNOWN' },
});
当我要求用户时,如何在一个命令/行中检索profile
?
User.findOne({ email: '[email protected]' })
我尝试填充,但没有用:
User.findOne({ email: '[email protected]' }).populate('profile')
- 请注意:我不想在同一架构的用户中拥有个人资料。
const UserSchema = new Schema({
profile: { type: Schema.Types.ObjectId, ref: 'Profile' },
email: { type: String, required: true },
name: { type: String, required: true },
password: { type: String },
picture: { type: String },
});
如何在一个命令中使用猫鼬检索配置文件和用户架构?
如何将用户和个人资料放在一起?
这是User
模式的定义方式:
const UserSchema = new Schema({
email: { type: String, required: true },
name: { type: String, required: true },
password: { type: String },
picture: { type: String },
});
和配置文件模式:
const ProfileSchema = new Schema({
user: { type: Schema.Types.ObjectId, ref: 'User' },
setting1: { type: String, enum: ['YES', 'NO', 'UNKNOWN'], default: 'UNKNOWN' },
setting2: { type: String, enum: ['YES', 'NO', 'UNKNOWN'], default: 'UNKNOWN' },
setting3: { type: String, enum: ['YES', 'NO', 'UNKNOWN'], default: 'UNKNOWN' },
});
当我要求用户时,如何在一个命令/行中检索profile
?
User.findOne({ email: '[email protected]' })
我尝试填充,但没有用:
User.findOne({ email: '[email protected]' }).populate('profile')
- 请注意:我不想在同一架构的用户中拥有个人资料。
const UserSchema = new Schema({
profile: { type: Schema.Types.ObjectId, ref: 'Profile' },
email: { type: String, required: true },
name: { type: String, required: true },
password: { type: String },
picture: { type: String },
});