cast to objectid failed for value object object at path -- mongoose

251 views
Skip to first unread message

mahesh tanneeru

unread,
Feb 14, 2014, 2:07:10 PM2/14/14
to mongoo...@googlegroups.com


i am new to NodeJS and MongoDB and ran through following problem while creating a sample app

   // ************  this is  testusers.js file  ************//

    var userdetails = require('userdetails');
    var mongoose = require('mongoose');
    var schema = mongoose.Schema;
    
    var geekDetails = new schema(
    {
        description:String,
        details:{
            type:mongoose.Schema.Types.ObjectId,
            ref:'userDetails'
        }
    });
    module.exports={
    model:mongoose.model('geekDetails',geekDetails),
    schema:geekDetails
    };


    // ************  this is  user.js file  ************//
    
    var mongoose = require('mongoose');
    var schema = mongoose.Schema;
    var userDetails = new schema({
    firstName :String,
    lastName : String,
    email:String,
    password:String
    });

    module.exports={
    model:mongoose.model('userDetails',userDetails),
    schema:userDetails
    };
     

    // ************  this is  create.js file [used to save the details to DB]  *******//
   
    var testusers = require('testusers.js');
    var mongoose = require('mongoose');
    
    adduser= function(firstName,lastName,email,password,passwordConfirmation,
                      description,callback){

                   new testusers.model({

                description:description,
                details:{
                    firstName:firstName,
                    lastName:lastName,
                    email:email,
                    password:password
                }

            }).save(function(err,result){

                if(err){callback(err,null);}
                    else{callback(null,result);}

        });



when i tried to save the details it returned the following error "**cast to objectid failed for value object object at path 'details'** " i am sure i am doing something wrong with schemas but i couldn't figure it out.

thanks in advance
Reply all
Reply to author
Forward
0 new messages