How to have user and profile together?
This is how User
schema defined:
const UserSchema = new Schema({
email: { type: String, required: true },
name: { type: String, required: true },
password: { type: String },
picture: { type: String },
});
and Profile schema:
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' },
});
How can I retrieve in one command/line the profile
when I ask for user?
User.findOne({ email: 'blabla@gmail.com' })
I have try populate but it is not works:
User.findOne({ email: 'blabla@gmail.com' }).populate('profile')
- Please notice: I don't want to have profile in user in the same schema.