2 回答
TA貢獻(xiàn)1808條經(jīng)驗(yàn) 獲得超4個(gè)贊
問(wèn)題是UserSchema.methods.toJSON方法沒(méi)有任何電子郵件字段,如果我們想過(guò)濾輸出數(shù)據(jù),最好通過(guò)mongoose.find({"condition"},{"fields"})
TA貢獻(xiàn)1827條經(jīng)驗(yàn) 獲得超9個(gè)贊
不要同時(shí)使用 .then 和 wait 。嘗試一次。假設(shè)模型是正確的。
const controller = {
fetchUsers :async (_req, res) => {
try {
const users=await User.find({}).exec()
if(users){
res.status(200).send(users);
}
else{
res.status(404).send("no user found");
};
} catch (error) {
res.status(500).json({
Error: `something is wrong. ${error}`,
});
}
}
}
添加回答
舉報(bào)
