Finding an Embedded Document by a specific property in Mongoose, Node.js, MongodDB

后端 未结 5 1656
不知归路
不知归路 2021-01-12 21:30

For this app, I\'m using Node.js, MongoDB, Mongoose & Express

So I have a Param Object that contains an array of Pivots, and I want to read certain data from the

5条回答
  •  日久生厌
    2021-01-12 22:00

    varunsrin,

    This should do it

    app.get('/:title/:value', function(req, res) {
      Param.findOne({'pivots.value': req.param('value'), "title":req.param('title')}},
                    function(err, record) {
                      record.pivot.counter++;
                      res.redirect(m_pivot.destination);  
                     record.save();
                   });
    });
    

    Note the pluralization of the query to match the field name in your schema

提交回复
热议问题