Organizational Research By

Surprising Reserch Topic

finding an embedded document by a specific property in mongoose node js mongod


finding an embedded document by a specific property in mongoose node js mongod  using -'mongodb,node.js,express,mongoose'

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 pivots as outlined below

---in models.js-------------------------
    var Pivot = new Schema({
    value : String
  , destination : String
  , counter : Number
 });


var Param = new Schema({
    title : String
  , desc : String
  , pivots : [Pivot]
});


------------- in main.js --------------

var Param = db.model('Param');


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


I know that the code works until console.log(record.pivots), since  i got a doc collection with the right pivot documents inside.

However, there does not seem to be a find method to let me match an embedded document by the 'value' property defined in the schema. Is it possible to search through this array of embedded documents using .find() or .findOne() , and if not, is there some easy way to access it through mongoose?
    

asked Sep 29, 2015 by okesh.badhiye
0 votes
8 views



Related Hot Questions

4 Answers

0 votes
NULL
answered Sep 29, 2015 by ashish singh
0 votes
NULL
answered Sep 29, 2015 by r3tt
0 votes
NULL
answered Sep 29, 2015 by shikhar jain
0 votes
NULL
answered Sep 29, 2015 by balvant maurya

...