I need multiple populate in the same query.
User.find({$or:[{region: "NA"},{sector:"Some Sector"}]}, function(err, user)
{
if (err)
{
res.send(err);
}
console.log(user);
res.json(user);});
CodePudding user response:
Post.model.js
const PostSchema = new Schema(
{
postTitle: {
type: String,
required: true,
},
users: [{ type: Schema.Types.ObjectId, ref: 'User' }],
},
{ timestamps: true },
);
Query like this
const posts = await Post.find()
.populate('users', '_id firstName lastName email');