简体   繁体   English

流星方法未在服务器上运行

[英]Meteor method not running on server

I have the following code,我有以下代码,

Meteor.methods({
  markPaid: function(expense) {
    check(this.userId, String);
    check(expense.id, String);

    Expenses.update({'_id': expense.id}, {$set: {paid: true}}, function(error) {
      return error;
    });
  }
});

called by被称为

Meteor.call('markPaid', expense, function(error, result) {
  //handle error if any.
});

When I call this from my client the code executes client side, as is expected with meteor's so-called optimistic UI, but the method does not run server side.当我从我的客户端调用它时,代码在客户端执行,正如流星所谓的乐观 UI 所预期的那样,但该方法不运行服务器端。 My actual database never updates.我的实际数据库永远不会更新。

Thank you!谢谢!

according the Meteor docs on Meteor.call (cf https://docs.meteor.com/api/methods.html#Meteor-call )根据 Meteor.call 上的 Meteor 文档(参见https://docs.meteor.com/api/methods.html#Meteor-call

Meteor.call(name, [arg1, arg2...], [asyncCallback]) Meteor.call(name, [arg1, arg2...], [asyncCallback])

ARGUMENTS论据

arg1, arg2... EJSON-able Object Optional method arguments arg1, arg2... EJSON-able Object 可选方法参数

the arguments must be JSON.参数必须是 JSON。 a moment object is not JSON.片刻对象不是 JSON。 that's why passing an id, as you did, works, but your full JS object does not.这就是为什么像您一样传递 id 有效,但您的完整 JS 对象无效。

Is the method being called inside observechanges?该方法是否在observechanges 中被调用? I had a similar issue:我有一个类似的问题:

let a = MyCollection.find({something:'something'}); 
a.observeChanges ({
    changed( id, fields) {
        console.log('Im here');
        Meteor.call ('awesomeMethod', 
            'param',
             (error, ans) => {
                 handel error; return; }                                    
                 console.log(ans);
             }
         );                
    }
});

And the same things were happening;同样的事情也在发生; only the simulation was running, but calling the method from the console worked well, so I decided to change the Meteor call to another place.只有模拟在运行,但是从控制台调用该方法效果很好,因此我决定将 Meteor 调用更改为其他地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM