-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
update failed: Access denied. Operator $setOnInsert not allowed in a restricted collection. #146
Comments
Okay, it looks like that if there is even single defaultValue in the whole(not necesseraly in the field you are trying to update) Schema then it does this. |
working work around for this was found from here: Meteor-Community-Packages/meteor-autoform#1582 (comment) const defaultValue = value => function autoValue() {
if (!this.isUpdate && !this.isUpsert && !this.isSet) {
return value;
}
};
// Schema field definition
fieldName: {
type: Number,
autoValue: defaultValue(10),
} It's not optimal, but atleast it works for now.. |
by the way if you didn't get that already, this is killing latency compensation for good |
See https://github.com/meteor/meteor/blob/master/packages/allow-deny/allow-deny.js#L354 @aldeed any thoughts on this? |
Seems like the proper thing to do would be to modify the Meteor |
Just in case anyone runs into this issue I can confirm that simply copying the allow-deny package from Meteor dev and modifying it to allow $setOnInsert is a good workaround. Sometime soon I'll submit a PR to Meteor if they don't fix it first. |
@hexsprite why does node-simple-schema need to use $setOnInsert? Why couldn't node-simple-schema simply replace the underlying logic for defaultValue to the one used here (Meteor-Community-Packages/meteor-autoform#1582 (comment))? |
@DerekTBrown yeah good question! |
This approach seems to have a major drawback: If you do it with an empty string, that field now validates only when there is some text -- setting the default to an empty string keeps 'clean' from clearing it out; doesn't do that with autorun. Set 'optional: true' on the field to fix this; but now you have to sort of deal with undefined, so it isn't ideal. |
If you are doing an upsert and you have a defaultValue, it assumes you want to set that default if your update ends up being an insert, same as what would happen if you do the The problem is with this comment here: https://github.com/aldeed/node-simple-schema/blob/ae35eafd7e593ff2694632c7004a5c1ebc0c1790/lib/SimpleSchema.js#L837-L838 We assume that Mongo won't mind the The checks like |
FYI, I've run into a problem that, while not necessarily caused by this, is exacerbating the problem. When specifying a default value for an array nested inside another array, you'll end up with positional operators in the $setOnInsert. Even when doing an update (without upsert), the cleaned modifier ends up containing something like {"layout.0.zones.$.align": "center"}. This causes mongo to reject the update. |
@pward123 Would you mind submitting a separate issue for that, including an example schema and example modifier that results in the issue happening? |
Hey guys! I'm getting this error while trying to update
profile.name
on clientside:Here is my
profile.name
schema (no autoValue or defaultValue!)..and here is the demonstration on chrome console

The text was updated successfully, but these errors were encountered: