javascript - How to populate a group in mongoose -
i have in mongoose schema...with group...
'use strict'; var mongoose = require('mongoose') , schema = mongoose.schema; var clientschema = new mongoose.schema({ name : { type: string }, offerings : [{ type: string }], cscpersonnel : { salesexec : { type: schema.types.objectid, ref: 'user' }, accountgm : { type: schema.types.objectid, ref: 'user' }, }, }, netpromoterscore : { type: number } }); module.exports = mongoose.model('clients', clientschema);
i tried populate reff dis way...i have populated in ref (user {path:'cscpersonnel'})
function getonebyid(id){ var deferred = q.defer(); console.log("im in id" +id); model .findone({ _id: id }) .populate({path:'cscpersonnel'})//one way /* 'cscpersonnel salesexec', //second way 'cscpersonnel accountgm', */ .exec(function (err, item) { if(err) { console.log(err); deferred.reject(err); } else console.log(item); deferred.resolve(item); }); return deferred.promise; } // gentonebyid method ends
but unfortunatly ended error!!!!
casterror: cast objectid failed value "[object object]" @ path "_id"
{ "message": "cast objectid failed value \"[object object]\" @ path \"_id\"", "name": "casterror", "type": "objectid", "value": { "salesexec": "56cf5f09245f8a240b30693b", "accountgm": "56cf5f09245f8a240b30693b" }, "path": "_id" }
how make solve issue.... do , in advance
please try one
model .findone({ _id: id }) .populate({path: 'cscpersonnel.salesexec'}) .populate({path: 'cscpersonnel.accountgm'}) .exec(function (err, item) {
Comments
Post a Comment