node.js - Mongoose get value from embedded document -
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
Post a Comment