just wondering how are we going to populate a query with multiple docs based on userId?
UserSchema
const UserSchema = new Schema({
email: {
type: String,
unique: true,
required: true,
},
hashValue: {
type: String,
required: true,
},
}, options);
FooSchema
const FooSchema = new Schema({
user: {
type: mongoose.Schema.Types.ObjectId,
required: true,
ref: 'User'
},
posts: {
type: String,
required: true,
},
}, options);
BarSchema
const BarSchema = new Schema({
user: {
type: mongoose.Schema.Types.ObjectId,
required: true,
ref: 'User'
},
sharedPosts: {
type: String,
required: true,
},
}, options);
what I want to achieve is something like
User.find({})
.populate('bar')
.populate('foo')
and the result should be look like this json
{
email: "x",
hashValue: "x",
foo: {...},
bar: {...}
}