简体   繁体   中英

Get data using node.js from mongoDB

I'm trying to get data from mongoDB. In my schema year - is not unique so I did the following:

 app.get('/getBestByYear/:year', function(req, res) {    
Stud.find({}).where('year').in(req.params.year).where('grade').gt(89).exec(function(err,students){
            if(err) throw err;
            res.json(students);
         });
     })

I get an empty string.. What did i do wrong?

you can try this code

console.log(req.params.year);   // show to verify year is valid
Stud.find({year: {$in: [req.params.year]}, grade: {$gt: 89}}).exec(function (err, students) {
    if (err) throw err;
    res.json(students);
})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM