Mongoose schema reference and undefined type 'ObjectID'
mongoose.Types.ObjectId
is the ObjectId
constructor function, what you want to use in schema definitions is mongoose.Schema.Types.ObjectId
(or mongoose.Schema.ObjectId
).
So deviceSchema
should look like this instead:
var deviceSchema = schema({ name : String, type : String, room: {type: mongoose.Schema.Types.ObjectId, ref: 'Room'}, users: [{type:mongoose.Schema.Types.ObjectId, ref: 'User'}]});