0

The below is my schema

var a = new Schema({
  d: {
    type: Schema.ObjectId,
    ref: 'Student'
  },
  e: {
    type: Schema.ObjectId,
    ref: 'Student'
  },
  f: {
    type: [{
      type: Schema.ObjectId,
      ref: 'Exam'
    }],
    select: true
  },   
});

Api.js

exports.updateClassSection = function(req,res){
  var _classSectionId = req.classSection._id;
  ClassSection
    .findOne({'_id':_classSectionId})
    .populate('d e')
    .exec(function(err,classSection){
      console.log("ClassSection");
      console.log(classSection);
      classSection.e=req.body.e;
      classSection.f=req.body.f;
      classSection.save().then(function(data){
        console.log("ClassSection saved");
      },function(err){
        console.log("Error");
        console.log(err);
      });
    });
};

I populate the objects 'e' and 'f'. but still , who do I get the error Cast to ObjectId failed for value "[object Object]" at path "e".. also it occurs at "f"

meriadec
  • 2,953
  • 18
  • 20
sabari
  • 2,595
  • 5
  • 28
  • 44
  • Probably because `req.body.e` isn't a valid ObjectId string. What does that string contain? – JohnnyHK Sep 23 '14 at 15:45
  • That contains the entire student object I assigned from my controller. Why is it not assigning to classSection.e ? – sabari Sep 24 '14 at 01:46

0 Answers0