Can't update a collection

Hello,
I’m new to Meteor and i met my first issue.
I’m using autoform and i need to update a collection from server. It works well with autoform.

//schema
Schemas.Enregistrement = new SimpleSchema({
//...
  type: {
    type: String,
    autoform: {
      type: 'hidden'
    },
    autoValue:function(){ return 'devis' }
  },
//...
});

//server
Enregistrements.update(enregistrementId, { $set: { type: 'facture' } });

//allow
Enregistrements.allow({
//...
  update: function (userId, doc) {
    return (userId && doc.user === userId);
  },
//...
});

Enregistrements.update callback doesent return any error and number = 1 as expected.
In Enregistrements.allow update, (userId && doc.user === userId) is returning true as expected too

But my collection is not updated :confused:

Any idea ? Thanks

Your autovalue is overwriting your submitted value on every update.

What is enregistrementId? Maybe you are not setting your Collection selector correctly?

You might also want to look at the mongo docs for find. This shows how to use a selector.

In your case, think you may want {_id: enregistrementId} as your selector.

:slight_smile: that is a good point too.

It was my first thought but no success

I’m using Collection2 and it seems i can use an id as selector. but {_id: enregistrementId} doesent work too :frowning:

Thanks for your answers.

I set up an alternative with autoform & jquery.

I will look for the bug later

Try like this instead…

//schema
Schemas.Enregistrement = new SimpleSchema({
//...
  type: {
    type: String,
    autoform: {
      type: 'hidden'
    },
    autoValue:function(){
        if(!this.isSet) {
            return 'devis';
        }
    }
  },
//...
});

Doesn’t work

I will look for a solution in few days. Jquery makes the stuff for now.

Thank you