2 回答
![?](http://img1.sycdn.imooc.com/5333a0350001692e02200220-100-100.jpg)
TA贡献2012条经验 获得超12个赞
你需要用这个运行 $where 。 https://docs.mongodb.com/manual/reference/operator/query/where/#example
async getAllProfiles() {
const profiles = await Profile
.find({$where:"this.activeProfile==true"})
.populate('user');
return profiles;
}
但是不是使用 $where 你可以在 find 中运行 cond,会更快
async getAllProfiles() {
const profiles = await Profile
.find({activeProfile: true})
.populate('user');
return profiles;
}
![?](http://img1.sycdn.imooc.com/533e4c1500010baf02200220-100-100.jpg)
TA贡献1735条经验 获得超5个赞
const getAllProfiles = () => {
return new Promise((resolve, reject) => {
Profile.find({activeProfile:true },(profileErr,profileRes)).populate('user').exec((profileErr,profileRes)=>{
if (profileErr) {
console.log('profileErr: ', profileErr);
reject({ status: 500, message: 'Internal Server Error' });
} else {
resolve({ status: 200, message: 'User Profile fetch Successfully.', data: profileRes })
}
});
});
}
它工作得很好!
添加回答
举报