node.js - Mongoose get value from embedded document -


enter image description herei have scheme this

 var wfworkitemdocument = new schema({         id: { type: string, required: true, unique: true, default: uuid.v1 },         description: { type: string },         period: [{             id: { type: string, default: uuid.v1 },             start: { type: date, default: date.now }             due: { type: number, integer: true },             new: { type: number, integer: true },         }], 

i want period's due value used method like

    workitem.findone({ id: idupdate }, function(err, workitem) {             if (err) {                 console.log("invlaid id");                 //return res.send(404, { error: 'invalid id' });             }              if (workitem) {                 console.log("id");                 console.log(workitem.period.due);              } else {                 //res.send(404, new error('workitem not found'));             } }); 

but doesn't work how can due value??

this result console.log(workitem)

change schema embed 1 object. unless need embedded array.

 var wfworkitemdocument = new schema({         id: { type: string, required: true, unique: true, default: uuid.v1 },         description: { type: string },         period: {             id: { type: string, default: uuid.v1 },             start: { type: date, default: date.now }             due: { type: number, integer: true },             new: { type: number, integer: true },         }, 

and if define embedded array, can access :

workitem.period[index].due


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -