[英]Pulling some values from Mongo DB but not all using nodejs with mongoose
下面是我的代码,它确实从数据库中提取了一些字段,但不是全部,我已经坚持了将近 2 天,请帮我修复这个错误。
我需要从 mongo DB 中提取数据,但无法提取所有字段
router.get('/areas', (req, res) => {
area
.find()
.exec()
.then((foundarea) => {
console.log(foundarea[0].name);
res.render('areas/areas.ejs', { areas: foundarea });
})
.catch((err) => {
if (err) {
console.log(err);
} else {
console.log(foundarea);
}
});
});
你可以试试这个:
area.find().select({"name":1, "column2":1})
.exec()
只需输入列的名称和 :1 即可将其包含在结果中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.