How to update collection for all doc (in client)?


#1

I want to update all docs in client like this

MyCollection.update({}, {$set: {fieldName: 'my value'}}, {multi: true});

But not work.


#2

From the documentation:

The behavior of update differs depending on whether it is called by trusted or untrusted code. Trusted code includes server code and method code. Untrusted code includes client-side code such as event handlers and a browser’s JavaScript console.

  • Trusted code can modify multiple documents at once by setting multi to true, and can use an arbitrary Mongo selector to find the documents to modify. It bypasses any access control rules set up by allow and deny. The number of affected documents will be returned from the update call if you don’t pass a callback.
  • Untrusted code can only modify a single document at once, specified by its _id. The modification is allowed only after checking any applicable allow and deny rules. The number of affected documents will be returned to the callback. Untrusted code cannot perform upserts, except in insecure mode.

If you want to update multiple documents, you will have to do it on the server (e.g. using a Meteor.method.


#3

Thanks, now it is OK on server