Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

field name 'type' cant access #2104

Closed
japrescott opened this issue May 27, 2014 · 2 comments
Closed

field name 'type' cant access #2104

japrescott opened this issue May 27, 2014 · 2 comments

Comments

@japrescott
Copy link

I have a really strange situtation; my schema has a fieldname which is called "type"

type: { type: String, default:"cow" }
the schema is extended by subclasses which override the type field name to change the default value

when I create the document and directly after the cb fires, find it and output the result to console.log, I see "type" and the value "cow" set as its value within the object.

when I access it with the mongo client, there is no field called "type". Getting just the type also doesn't show any document that have that field using this command

db.items.find({},{type:1}).pretty();
in a other script (that executes later), I get the document with mongoose again and there is also no "type" field there either.

Is "type" some special no-no word? My schema worked fine since ages and stopped working recently.

Thanks for your help MongoDB: 2.4.9 Mongoose: 3.8.5

@japrescott
Copy link
Author

I was discussing this issue here (more source code) -> http://stackoverflow.com/questions/23879960/fieldname-type-in-my-schema

and was able to fix it by specifically setting type:"cow" when creating the document and not relying on the default schema attribute taking care of that for me. Is the schema's default attribute broken at the moment?

@vkarpov15
Copy link
Collaborator

This is something we need to make a bigger deal of in the docs: basically, don't put fields named type in your schema. Mongoose assumes that type means you're trying to set the type of the path in the schema, so { a: { type: { type: String, default:"cow" } } will make mongoose think that you're trying to say that a should be of type { type: String, default:"cow" }. I would recommend you rename type -> kind or something similar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants