Update field in Meteor db

Hello, i try to update a Laws collection inside Meteor using a method.
I can’t seem to use the update method properly

The callback function
    handleSubmit(e){
        e.preventDefault();
        const titleLoi=e.target.titleLoi.value;
        const abstractLoi=e.target.abstractLoi.value;
        if(titleLoi){
            Meteor.call('laws.update', titleLoi, abstractLoi); 
        }
    };

And the server side

'laws.update': function(titleLoi, abstractLoi){
    return  Laws.update ({
      $set:{title:titleLoi, abstract:abstractLoi}
    });
  },

I try to update two fileds in the document.

Thank you for your help (very newbie question, sorry!)

You need to supply an identifier for which document you’d like to update.

A collection can have multiple documents, and each document has a unique identifier so that you can find/reference it. Your update statement should look more like this:

Laws.update({ _id: lawId }, { $set: { title:titleLoi, abstract:abstractLoi } });

edit: if you want to update every document in the collection you can do so like this:

Laws.update({}, { $set: { title:titleLoi, abstract:abstractLoi } }, { multi: true });
3 Likes

Thank you @bmanturner, I could make it work passing along the props.law to meteor.call. Best