Meteor-Community-Packages / meteor-collection2

A Meteor package that extends Mongo.Collection to provide support for specifying a schema and then validating against that schema when inserting and updating.
https://packosphere.com/aldeed/collection2
MIT License
1.02k stars 108 forks source link

Using update to replace entire document raises error #383

Closed twiddler closed 3 years ago

twiddler commented 6 years ago

I am using simpl-schema and attachSchema() with uniforms. The following code

<Uniforms.AutoForm
  schema={myschema}
  onSubmit={doc => mydb.update({/* ... */}, doc)}}
  /* ... */
/>

leads to

modules.js?hash=e18a1fcdefa12dc238864b005e7781729a89890e:49044 Uncaught (in promise) Error: Expected 'mykey' to be a modifier operator like '$set' at modules.js?hash=e18a1fcdefa12dc238864b005e7781729a89890e:49044 at Array.forEach () at checkModifier (modules.js?hash=e18a1fcdefa12dc238864b005e7781729a89890e:49040) at doValidation (modules.js?hash=e18a1fcdefa12dc238864b005e7781729a89890e:49084) at ValidationContext.validate (modules.js?hash=e18a1fcdefa12dc238864b005e7781729a89890e:48638) at doValidate (collection2.js:433) at _class.Mongo.Collection.(anonymous function) [as update] (http://127.0.0.1:3000/packages/aldeed_collection2.js?hash=467c40267ae685e6929f20ef17989e35bd382a53:286:14) at _class. (matb33_collection-hooks.js?hash=f1f87bc2e36c884177945d27780c5feac3f558c7:513) at _class.collection.(anonymous function) [as update] (http://127.0.0.1:3000/packages/matb33_collection-hooks.js?hash=f1f87bc2e36c884177945d27780c5feac3f558c7:155:21) at Object.onSubmit (Person.js:50)

while

<Uniforms.AutoForm
  schema={myschema}
  onSubmit={doc => mydb.update({/* ... */}, {$set: doc})}}
  /* ... */
/>

works fine. I might be mistaken, but from https://docs.mongodb.com/manual/reference/method/db.collection.update/#replace-a-document-entirely I expected the first snippet to work. Maybe I am missing something, I am just getting started with Meteor and all these packages.

twiddler commented 6 years ago

https://docs.meteor.com/api/collections.html#modifiers reads

Literal document modifiers are not currently supported by validated updates.

but does not go into details what those "validated updates" are. But maybe that is the issue here? I have autopublish and insecure packages still enabled.

StorytellerCZ commented 3 years ago

Closing as it is duplicate of #368