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

Dot operator not fetching child properties of a Mongoose Document object #2378

Closed
laggingreflex opened this issue Oct 14, 2014 · 2 comments
Closed
Milestone

Comments

@laggingreflex
Copy link

I have a mongoose schema less schema

var User = new mongoose.Schema({}, {
    strict: false,
});

and any object I save with it, seems to contain the properties that I saved

console.log(user); /* =>
{ username: 'user1',
  salt: '3303187e50a64889b41a7a1c66d3d3c10b9dec638fdd033bee1221d30d01c5e1',
  hash: 'a174c206d88bee1594bb081dbd32d53420f6ef3d6322104f3d0722d58bc8dd8d',
  _id: 52d3177481daf59c11000001,
  __v: 0 } */

but when I try to access those properties individually with a dot operator, it outputs undefined!!

console.log(user.hash); // => undefined

What could be causing this?

This only happens with the properties that aren't declared in the schema. If I declare hash in the schema it works. Is this by design? (that you can't access schema-less properties) And even if so, how is it even achieved - not allowing access properties with dot operator?

@vkarpov15
Copy link
Collaborator

Hmm this may be a bug with unstrict schemas. Can you tell me what version of mongoose you're using?

@vkarpov15 vkarpov15 added this to the 3.8.19 milestone Oct 17, 2014
@laggingreflex
Copy link
Author

I'm using 3.8.17

SO thread has more details and discussion on the issue.

alabid added a commit to alabid/mongoose that referenced this issue Nov 4, 2014
vkarpov15 added a commit that referenced this issue Nov 5, 2014
gh-2378 enable getters for properties defined with non-strict schemas; u...
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

3 participants