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

$inc doesn't work correctly on sub-objects (unless bypassCollection2 is present) #388

Open
lcampanis opened this issue Sep 1, 2018 · 0 comments

Comments

@lcampanis
Copy link

Consider the following setup (from ReactionCommerce):

import { Accounts as AccountsCollection } from "/lib/collections";

// A schema extension (Extending isn't a problem)
Accounts.extend({
  "incParent": {
     type: Object,
     defaultValue: {},
     optional: true
  },
  "incParent.$": {
     type: Number
  }
});
AccountsCollection.attachSchema(Accounts);

// Call from a method
Accounts.update({
  _id: this.userId
}, {
  $inc: {
    "incParent.subKey1": 10
  }
}, {
  bypassCollection2: true // without this "incParent.subKey1" isn't even created
});

Without bypassCollection2 there is no error and only works if you do $inc: { key: 10 } (but not on a subkey).

You can have:

$inc: {
  key: 10
  "incParent.subKey1": 10
}

and will update only key and not "incParent.subKey1".

With bypassCollection2: true works fine, but isn't correct, hence the issue.

Let me now if you need more info.

Thank you.

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

No branches or pull requests

2 participants