How should I query Mongo DB using end point API?

Viewed 83

I am new to programming. I have an API connected to a MongoDb. Now, I am trying to query MongoDB with simple queries such:

What players had red or yellow cards? in mongo DB shell I could run: db.information.find( {$or: [{red_card:{ $gt : 0 }} ,{yellow_cards:{ $gt: 0}}]});

However, I need to run this query with one or multiple endpoints. How should I do that?

This is my route for team id:

    router.route('/team/:team_id')
    .get(teamController.view)
    .patch(teamController.update)
    .put(teamController.update)
    .delete(teamController.delete);

This is my controller call:

exports.view = function (req, res) {
    Team.findById(req.params.team_id, function (err, team) {
        if (err)
            res.send(err);
        res.json({
            message: 'Info Details',
            data: team
        });
    });
};

(...)

How would I query the DB using the same structure? Or what are your suggestions to represent that query

Thank you!

0 Answers
Related