我无法在nodejs中通过以下代码获得数据?它显示TypeError:将循环结构转换为JSON &g


app.get('/students', (req, res)=>{
const studentsData = Student.find();
studentsData.then(()=>{
res.status(200).send(studentsData);
}).catch((e)=>{
console.log(e);
res.status(400).send(e);
})
})

我得到的错误说:-TypeError:将循环结构转换为JSON

你应该使用承诺的结果来返回,而不是承诺本身:

app.get('/students', (req, res)=>{
const studentsData = Student.find();
studentsData.then(result => {
res.status(200).send(result);
}).catch((e)=>{
console.log(e);
res.status(400).send(e);
})
})

相关内容

最新更新