Re: [mongoose] Cannot read property 'name' of undefined.

667 views
Skip to first unread message

Jason Crawford

unread,
Jan 20, 2014, 11:54:23 AM1/20/14
to mongoo...@googlegroups.com
I don't think you can pass a simple object like {name: String} to mongoose.model(). I think it needs to be a Mongoose Schema object. Create the schema object first, then pass that to mongoose.model(). See the guide for an example: http://mongoosejs.com/docs/guide.html

Hope that helps,
Jason

--
Blog: http://blog.jasoncrawford.org  |  Twitter: @jasoncrawford




On Mon, Jan 20, 2014 at 1:03 AM, Vicary Archangel <den...@gmail.com> wrote:
I have seen similar title in this forum, but the case looks not so similar. So I'm filing another one here.

My code is simply like this:
var Cat = mongoose.model('Cat', { name: String });

Then I got an error with context like this:
./node_modules/mongoose/lib/index.js:305
  if (!this.modelSchemas[name]) {
                        ^

TypeError: Cannot read property 'Issue' of undefined

I tried to console log the "this" context in the method Mongoose.prototype.model, which shows an empty object.

It seems for whatever reason, the Mongoose prototype cannot access it's constructor contents.

Curious enough, it was working until I added "marked" into my package.json.

Is it about npm or JavaScript, or it is me?

--
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/groups/opt_out.

Aaron Heckmann

unread,
Jan 21, 2014, 10:52:16 PM1/21/14
to mongoo...@googlegroups.com
You can pass object literals for schemas as of 3.6 https://github.com/LearnBoost/mongoose/wiki/3.6-Release-Notes#object-literal-schema-support

Create a test case that works. Then add marked. If it breaks, post the code so we can run and debug.


--

Reply all
Reply to author
Forward
0 new messages