2016-02-28 3 views
0

У меня есть это в моей мангустовой схеме ... с некоторой группой ...Как заполнить группу в мангусте

'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); 

Я попытался заполнить REFF Дис пути ... Я также заселен ссылок (пользователь как {путь: ''} cscPersonnel)

function getOneById(id){ 
    var deferred = Q.defer(); 
console.log("im in get by 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 

но, к сожалению закончилась с этой ошибкой !!!!

CastError: Cast до ObjectId Сбой значения "[объект Object]" на пути "_id"

{ 
    "message": "Cast to ObjectId failed for value \"[object Object]\" at path \"_id\"", 
    "name": "CastError", 
    "type": "ObjectId", 
    "value": { 
    "salesExec": "56cf5f09245f8a240b30693b", 
    "accountGM": "56cf5f09245f8a240b30693b" 
    }, 
    "path": "_id" 
} 

как сделать его решить эту проблему .... сделать помощь, заранее спасибо

ответ

1

Пожалуйста, попробуйте это один

model 
    .findOne({ _id: id }) 
    .populate({path: 'cscPersonnel.salesExec'}) 
    .populate({path: 'cscPersonnel.accountGM'}) 
    .exec(function (err, item) { 
+0

действительно большое спасибо soooooooooooooo много ... жизнь спасителя !!!!!!!!!!!!!! –

+0

@swatikiran, пожалуйста, задайте другой вопрос для своей новой проблемы. – zangw

Смежные вопросы