Saturday, 1 April 2017

mongoose Getting a nested field value from a queried document

I am new to Node js and Mongoose and I am stuck with this one query.

exports.getIndividual=(matchId,phone)=>
 new Promise((resolve,reject)=>{
 var e="matchPersonal.m"+matchId+".bo1";
 query={};
 query[e]=1;

 var quer=usersc.findOne({phone:"8989898980"}).select(query);
 quer.exec(function (err, matc) { 

 var m=matc.toObject();

 console.log('',m);

When I Run this query I get on my console this thing

        {matchPersonal:{m1:{bo1:3}}}

But I just need 3 as my output and I cant use dot operator to read the object properties directly because

   var b=matchPersonal.m+matchId.bo1

doesnt work as '+' cant be used here so please help



via learn_ing

No comments:

Post a Comment