Mongoose: TypeError: Invalid value for schema path | Schema.ObjectID issue

Created on 18 Jun 2012  路  7Comments  路  Source: Automattic/mongoose

Running on OSX Snow Leopard. Not sure exactly which version of mongoose I'm using, but I just installed it today with

npm install mongoose

The code seems to be choking when I use ObjectID as the datatype for a schema field. When I change ObjectID to say String, the error disappears.

Console Output:

bretts-Mac-mini:node_code brett$ sudo node example.js 

/Users/brett/Desktop/node_code/node_modules/mongoose/lib/schema.js:108
      throw new TypeError('Invalid value for schema path `'+ prefix + i +'`');
            ^
TypeError: Invalid value for schema path `definition_id`
    at Schema.add (/Users/brett/Desktop/node_code/node_modules/mongoose/lib/schema.js:108:13)
    at new Schema (/Users/brett/Desktop/node_code/node_modules/mongoose/lib/schema.js:38:10)
    at Object.<anonymous> (/Users/brett/Desktop/node_code/example.js:28:30)
    at Module._compile (module.js:446:26)
    at Object..js (module.js:464:10)
    at Module.load (module.js:353:31)
    at Function._load (module.js:311:12)
    at Array.0 (module.js:484:10)
    at EventEmitter._tickCallback (node.js:190:38)

Source

var mongoose = require('mongoose');


var DefinitionRatingSchema = new mongoose.Schema({
    definition_id     : mongoose.Schema.ObjectID
  , rating            : Number
});

Most helpful comment

Should be mongoose.Schema.ObjectId instead of mongoose.Schema.ObjectID .

Perhaps a more descriptive error message would be helpful. Something like: "Invalid Schema Type"

All 7 comments

Should be mongoose.Schema.ObjectId instead of mongoose.Schema.ObjectID .

Perhaps a more descriptive error message would be helpful. Something like: "Invalid Schema Type"

Wow, i just stumbled on the same error. The error message is so cryptic

just to highlight in ObjectId, d is small.
Facing this error from yesterday, stumbled on this post twice, just figured what was wrong.

agreed...cryptic message. I had not capitalized the "O" in objectId. thanks for the info all.

When you Google the error message, this issue page is the top result. So the error message is officially useful now? (My "d" was also uppercase; changed it and it solved the problem)

In my case I had a small 'm' in mongoose.Schema.Types.mixed instead of mongoose.Schema.Types.Mixed. Hope that helps someone else in the future.

I had "ID". Much gratitude to those who are responsible for this thread. Thanks.

Was this page helpful?
0 / 5 - 0 ratings