2 回答

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;
}

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 })
}
});
});
}
它工作得很好!
添加回答
舉報