【发布时间】:2016-10-09 21:37:53
【问题描述】:
我有 mongodb 集合,我需要从中提取高中和大学到各自的路线。 我的收藏是这样的
{ “_id”:“1f24ef0c-6f9c-478a-adc9-7c55d7708930”, “高中”:“现代修道院”, “学院”:“史蒂文斯理工学院” }
我的路线如下所示:-
const data = require("../data");
const educationData = data.education;
router.get("/highschool", (req, res) => {
educationData.getHighSchool().then((education) => {
res.json(education);
}, () => {
// Not found!
res.sendStatus(404);
});
});
router.get("/", (req, res) => {
educationData.getAllEducation().then((EducationList) => {
res.json(EducationList);
}, () => {
// Something went wrong with the server!
res.sendStatus(500);
});
});
我的“/”路线返回 id、大学和高中。但是在“/highschool”中,我只想提取集合中存在的高中的名称。我怎样才能做到这一点。目前我正在使用以下函数来返回数据。
const education = mongoCollections.education;// added for reference
return education().then((educationCollection) => {
return educationCollection.find({}).toArray();
});
},
getHighSchool(){
return education().then((educationCollection)=> {
return educationCollection.highSchool;
});
}
“getAllEducation”函数返回所有内容,但“getHighSchool”没有返回任何内容。
【问题讨论】:
-
你的观点是谁?您的代码中缺少
getAllEducation,对吗?
标签: node.js mongodb express es6-promise