【发布时间】:2016-03-10 22:35:04
【问题描述】:
我正在使用 MongoDB、Ember、Express 和 Node 制作应用程序。
我的成绩模型定义如下:
export default DS.Model.extend({
mark: DS.attr(),
section: DS.attr(),
student: DS.belongsTo('student', { async: true }),
coursecode: DS.belongsTo('coursecode', { async: true }),
programrecord: DS.belongsTo('programrecord', { async: true })
});
而我的学生模型定义如下:
export default DS.Model.extend({
number: DS.attr(),
firstName: DS.attr(),
lastName: DS.attr(),
DOB: DS.attr(),
resInfo: DS.belongsTo('residency',{ async: true }),
gender: DS.belongsTo('gender',{ async: true }),
country: DS.belongsTo('country',{ async: true }),
province: DS.belongsTo('province',{ async: true }),
city: DS.belongsTo('city',{ async: true }),
grades: DS.hasMany('grade', { async: true }),
});
我正在发出获取请求以查询具有特定标记的所有等级:
GET to /grades?mark=100
我也在发出一个 get 请求来查询属于特定学生的成绩(不确定我是否正确执行此操作,我正在传递学生对象的 ID):
GET to /grades?student=56d33a7896c31b6b1e40446a
如何在 server.js 文件中定义 路由 来响应这个问题,这样我就可以只返回标记为 100 的成绩对象,或者只返回属于的成绩对象一个学生?
【问题讨论】:
-
可以查看请求参数,判断客户端发送的是什么参数,然后根据该参数返回
标签: node.js mongodb express ember.js