question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 11 years ago
  • Comments:7

github_iconTop GitHub Comments

23reactions
brett-shwomcommented, Jun 18, 2012

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

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

6reactions
enVoltcommented, Feb 12, 2016

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error when using _id as a property type in a Mongoose Schema
The the problem comes from author: User.userId , but I don't know how to make a reference between the two tables. For reference,...
Read more >
TypeError: Invalid value for schema path `genre.type`, got ...
I'm learning Node.js and trying to build a simple application for movie rentals service. This is my code for defining schema for movies...
Read more >
Mongoose Schemas v4.13.20
Mongoose will emit an index event on the model when indexes are done building or an error occurred. // Will cause an error...
Read more >
Re: [mongoose] problem embedding schema - Google Groups
TypeError : Invalid value for schema path `meta` ... and that I should, in this case, use an object ID, i.e., make a...
Read more >
cannot populate path because it is not in your schema.
MongooseError: Cannot populate path friends because it is not in your schema. Set the strictPopulate option to false to override. I want to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found