小编And*_*ord的帖子

在服务器上调用Collection.insert时,"Meteor代码必须始终在Fiber中运行"

我在server/statusboard.js中有以下代码;

var require = __meteor_bootstrap__.require,
    request = require("request")   


function getServices(services) {
  services = [];
  request('http://some-server/vshell/index.php?type=services&mode=json', function (error, response, body) {
    var resJSON = JSON.parse(body);
     _.each(resJSON, function(data) {
       var host = data["host_name"];
       var service = data["service_description"];
       var hardState = data["last_hard_state"];
       var currState = data["current_state"];
       services+={host: host, service: service, hardState: hardState, currState: currState};
       Services.insert({host: host, service: service, hardState: hardState, currState: currState});
    });
  });
}

Meteor.startup(function () {
  var services = [];
  getServices(services);
  console.log(services);
});
Run Code Online (Sandbox Code Playgroud)

基本上,它从JSON提要中提取一些数据并尝试将其推送到集合中.

当我启动Meteor时,我得到以下异常;

app/packages/livedata/livedata_server.js:781
      throw exception;
            ^
Error: Meteor …
Run Code Online (Sandbox Code Playgroud)

javascript meteor node-fibers

38
推荐指数
3
解决办法
2万
查看次数

标签 统计

javascript ×1

meteor ×1

node-fibers ×1