我正在创建我的第一个rest api,并且已经完成了findbyId,find,delete,update部分。现在我需要过滤出我已经搜索出方法的数据,但是我听不懂它们。问题:我有程序集合,并且有学科领域,我想根据学科名称过滤出结果。这是我的代码
app.get('/api/programs/', function(req,res)
{
disc = req.query.discipline;
console.log(disc)
//by query parameter
Programs.find({where : { _discipline: disc }},function(err,progData)
{
if(err)
{
throw err;
}
res.json(progData);
} );
url: http://localhost:3000/api/programs/?discipline=Engineering
程序架构:
var progSchema = mongoose.Schema
({
uni_name: String,
program_name: String,
degree_name: String,
duration: String,
fee_per_year: String,
admission_date: String,
last_merit: String,
discipline: String,
About_Disc: String
});
此代码不起作用,它返回空[],但是数据库包含所需的数据。 如果您有更好的解决方案,请提出建议。
答案 0 :(得分:0)
知道了 需要将集合名称添加为
var progSchema = mongoose.Schema
({
uni_name: String,
program_name: String,
degree_name: String,
duration: String,
fee_per_year: String,
admission_date: String,
last_merit: String,
discipline: String,
About_Disc: String
},
{ collection: "Engineering" }
);