cant assign schema type ObjectId: Cannot read property 'ObjectId' of undefined

1,562 views
Skip to first unread message

David Z

unread,
Feb 21, 2015, 7:45:58 PM2/21/15
to mongoo...@googlegroups.com

According to this doc here I should be allowed to do this:

var UserTag = Schema({



   
User: Schema.Types.ObjectId,

    users_tagged
: [User]



});


however doing so produces this error:

    User: Schema.Types.ObjectId,

                     
^

TypeError: Cannot read property 'ObjectId' of undefined


Does anyone know what the deal is here?

Jason Crawford

unread,
Feb 21, 2015, 7:49:40 PM2/21/15
to mongoo...@googlegroups.com
Works for me (although I'm on an earlier version of Mongoose, 3.6.11).

How are you getting Schema? What's your require statement?

--
Documentation - http://mongoosejs.com/
Plugins - http://plugins.mongoosejs.com/
Bug Reports - http://github.com/learnboost/mongoose
Production Examples - http://mongoosejs.tumblr.com/
StackOverflow - http://stackoverflow.com/questions/tagged/mongoose
Google Groups - https://groups.google.com/forum/?fromgroups#!forum/mongoose-orm
Twitter - https://twitter.com/mongoosejs
IRC - #mongoosejs
---
You received this message because you are subscribed to the Google Groups "Mongoose Node.JS ODM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

David Z

unread,
Feb 21, 2015, 7:51:37 PM2/21/15
to mongoo...@googlegroups.com
Hey Jason thanks for your reply. My require statement is:

var Schema = require('mongoose').Schema;


I am using version 3.8.23 of mongoose.

David Z

unread,
Feb 21, 2015, 7:54:42 PM2/21/15
to mongoo...@googlegroups.com
I just tried 3.6.11 and the problem persists

Jason Crawford

unread,
Feb 21, 2015, 7:55:59 PM2/21/15
to mongoo...@googlegroups.com
No idea. It should work. I would look at that Schema object and see what other properties is has, and doesn't have. Maybe you're getting an empty object somehow… maybe something went wrong with your require. Not sure. Sorry I can't be more help.

On Sat, Feb 21, 2015 at 4:54 PM, David Z <mac...@gmail.com> wrote:
I just tried 3.6.11 and the problem persists

--

Valeri Karpov

unread,
Feb 25, 2015, 3:30:00 PM2/25/15
to mongoo...@googlegroups.com
Works fine for me on 3.8.23. Just to make sure it's not an issue with your code, can you run the below script and see if you get the error:

```

var mongoose = require('mongoose');

var Schema = mongoose.Schema;


console.log(require('util').inspect(Schema.Types.ObjectId));

```

If that doesn't throw any errors, I would suspect somewhere you have a variable named Schema that's occluding the `var Schema = require('mongoose').Schema`

To unsubscribe from this group and stop receiving emails from it, send an email to mongoose-orm+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages