TypeError: Invalid value for schema path | Schema.ObjectID issue
See original GitHub issueRunning 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:
- Created 11 years ago
- Comments:7
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub 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”
just to highlight in ObjectId,
d
is small. Facing this error from yesterday, stumbled on this post twice, just figured what was wrong.