Mongoose find() doesn't filter result

Viewed 33

I am building a Node.js application and using Mongoose to get vehicle makes from the database ("make": "ACURA" for instance). Here is my GET router code below. I am trying to filter the cars dataset for a specific make. Param Make (req.query.make) is passed in just fine with no issues. Postman and console.log return not filtered docs though but I do get all data back instead. What am I doing wrong? Thank you

router.get('/year', (req,res) => {
    console.log(req.query.make);

    vehicles.find().where('make').equals(req.query.make).exec(function(err, data){
        res.send(data);
    });

});

My initial JSON docs set

{
        "_id": "62c5a4ed1cb20b8d81ba70ae",
        "year": 2001,
        "make": "BMW",
        "model": "X5"
    },
    {
        "_id": "62c5a4ed1cb20b8d81ba70af",
        "year": 2001,
        "make": "ACURA",
        "model": "EL"
    },
0 Answers
Related