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

后端 未结 5 1588
不知归路
不知归路 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:11

    You can querying using embedded document properties like this:

    {'pivot.value': req.param('value')}}
    

    Update in response to comment:

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

提交回复
热议问题