node.js - Data not populating in mongoose -


here schema

var employee =       {         empcode : { type : string  ,  unique: true ,  required : true },         firstname : { type : string  , required : true },         lastname : { type : string },         email :  { type : string  },         doj :{ type : date , default: date.now },         dob :{ type : date  },         phoneno : { type : string },         authentication :              {                 username : { type : string },                 password : { type : string }             },         dsg :              [{                 designationid: [{type : mongoose.schema.objectid , ref:'designation'}],                 efffrom :{ type : date , default: date.now },                 effto : { type : date }                          }],         grd :              {                 grade : [{type : mongoose.schema.objectid, ref:'grade'}],                 efffrom :{ type : date , default: date.now },                 effto : { type : date }             },         dpt :             {                 departmentid : [{type : mongoose.schema.objectid ,ref:'department'}],                 efffrom :{ type : date , default: date.now },                 effto : { type : date }             },         manager :              {                 managerid : {type : mongoose.schema.objectid , ref:'employee'},                 efffrom :{ type : date , default: date.now },                 effto : { type : date }             },         rol :             {                    roleid : [{type : mongoose.schema.objectid , ref:'role'}],                 efffrom :{ type : date , default: date.now },                 effto : { type : date }             },          status : {type:boolean}     } 

and wannt populate

empcontroller.prototype.list=function(callback){     objmdlemp.find()     .populate('designationid')     .populate('grade')     .exec(function(err, records){         if(err){             console.log(err);return;             callback(false , config.msg.somthing_wrong);             return;         }else {             callback(true , records);            }     }) }; 

but document data not showing, when put schema showing , need add efffrom , effto data also

dsg : [{type : mongoose.schema.objectid , ref:'designation'}]

you cant populate embedded fields in mongoose, can use workarounds

1) keep related data in field so

var employee = {     grd: {type: mongoose.schema.objectid, ref: 'grade'},     grddata: {         grade: [],         efffrom: {type: date, default: date.now},         effto: {type: date}     } }; 

2) use plugins mongoose-deep-populate

objmdlemp.find().deeppopulate('grd.grade').exec(function (err, records) { ... }); 

Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -