meteor/meteor

Method only runs once on server, simulation on client does run - 3.0-rc.0

poetsmeniet opened this issue · 4 comments

OS: Debian 12
Expected behaviour: calling the method should update the collection every time it is called by the client.
Actual behaviour: the method is only run once on the server.

The server method:

  'parameters.upsert': function(orgId, parametersArr) {
  console.log('upsert params (orgId: ', orgId, '): ', parametersArr);
   
  Parameters.upsertAsync({orgId: orgId}, {
    createdAt: new Date(),
    orgId: orgId,
    parametersArr: parametersArr
  })
 .then(result => {
    console.log('Upsert operation successful:', result);
    return result;
  })
 .catch(error => {
    console.error('Error during upsert operation:', error);
    throw error; 
  });
}

On the client:
async function test(){
await Meteor.call('parameters.upsert', 1, paramArr, (e, res) =>{
if(res) handleClose(1);
console.log('paramters.upsert came back: e: ', e, ' and res: ', res);
});
}

im not super good but shouldn't the 'function' be 'async function'?

Otherwise what happens when:


  'parameters.upsert': async function(orgId, parametersArr) {
  console.log('upsert params (orgId: ', orgId, '): ', parametersArr);
   try {
   const result =  await Parameters.upsertAsync({orgId: orgId}, {
    createdAt: new Date(),
    orgId: orgId,
    parametersArr: parametersArr
  }) 
    console.log('Upsert operation successful:', result);
    return result;
  } catch {
    console.error('Error during upsert operation:', error);
    throw error; 
  };
return this.ready()
}

When I make it more simple, like this:

  'parameters.upsert': async function(orgId, parametersArr){
    console.log('upsert params (orgId: ',orgId,'): ', parametersArr);
    const res = await Parameters.upsertAsync({orgId: orgId},
      {
        createdAt: new Date(),
        orgId: orgId,
        parametersArr: parametersArr
      }
    );
    return res;
  }
  await Meteor.call('parameters.upsert', 1, paramArr, (e, res) =>{
     if(res) handleClose(1);
     console.log('paramters.upsert came back: e: ', e, ' and res: ', res);
   });

Console output after first page load:
paramters.upsert came back: e: undefined and res:
Object { numberAffected: 1 }
​numberAffected: 1
​: Object { … }

The second time I call the method, this is console output:
paramters.upsert came back: e: undefined and res:
Promise { : "pending" }
​: "fulfilled"
​: Object { numberAffected: 1 }
​: Promise.prototype { done: done(onFulfilled, onRejected), … }

What happens when you use Meteor.callAsync instead?

What happens when you use Meteor.callAsync instead?

Yes, that does work. So simple :D