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

mongoose leaking fields between objects #1380

Closed
azylman opened this issue Mar 12, 2013 · 2 comments
Closed

mongoose leaking fields between objects #1380

azylman opened this issue Mar 12, 2013 · 2 comments
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.

Comments

@azylman
Copy link

azylman commented Mar 12, 2013

If I create an object "property one" with a field data that has a mixed schema type, leave it empty, fetch that property from the database, set the data field, save it, create a second property ("property two"), leave the data field empty, save it to the database, then look it up, the data field is now populated with the same data as the first property.

My guess is that it's related to the lack of minimize: false.

https://gist.github.com/azylman/5139583

@aheckmann
Copy link
Collaborator

Mongoose is behaving properly. The data field has its default set to a single object instance, therefore all documents will have their default data field set to this instance. If you'd like to use a different instance for each document, set the default to a function that returns an object literal.

Schema({ data: { type: Mixed, default: function () { return {} } }})

I'd like to change this (its come up before) but it should probably wait til 4.x.

@aheckmann aheckmann reopened this Mar 12, 2013
@aheckmann
Copy link
Collaborator

on second thought, this is really lame. lets just fix this for 3.6 and point out the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug We've confirmed this is a bug in Mongoose and will fix it.
Projects
None yet
Development

No branches or pull requests

2 participants