Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Meteor:collection.find().fetch()在Deps.autorun中失败_Meteor - Fatal编程技术网

Meteor:collection.find().fetch()在Deps.autorun中失败

Meteor:collection.find().fetch()在Deps.autorun中失败,meteor,Meteor,我想在meteor服务器上创建一个反应式收集查询,并在发生更改时处理结果 这是我的密码: if (Meteor.isServer) { Meteor.startup(function(){ Deps.autorun(function(){ var items=new Meteor.Collection('name').find().fetch(); // ... process the items ... }); }); } (事实上,对于这个测

我想在meteor服务器上创建一个反应式收集查询,并在发生更改时处理结果

这是我的密码:

if (Meteor.isServer) {
  Meteor.startup(function(){
    Deps.autorun(function(){
      var items=new Meteor.Collection('name').find().fetch();
      // ... process the items ...
    });
  });
}
(事实上,对于这个测试,整个项目只包含一个.js文件中的上述代码)。 使用meteor启动此程序会引发错误:

/home/yaakov/Bug/.meteor/local/build/programs/server/boot.js:198
}).run();
   ^
Error: Can't call yield in a noYieldsAllowed block!
    at Function.Fiber.yield (packages/meteor/fiber_helpers.js:11)
    at Function.wait (home/yaakov/.meteor/tools/cef2bcd356/lib/node_modules/fibers/future.js:111:14)
    at Object.Future.wait (/home/yaakov/.meteor/tools/cef2bcd356/lib/node_modules/fibers/future.js:325:10)
    at new MongoConnection (packages/mongo-livedata/mongo_driver.js:196)
    at new MongoInternals.RemoteCollectionDriver (packages/mongo-livedata/remote_collection_driver.js:4)
    at Object.<anonymous> (packages/mongo-livedata/remote_collection_driver.js:44)
    at Object.defaultRemoteCollectionDriver (packages/underscore/underscore.js:750)
    at new Meteor.Collection (packages/mongo-livedata/collection.js:72)
    at app/Bug.js:4:17
    at packages/deps/deps.js:47
/home/yaakov/Bug/.meteor/local/build/programs/server/boot.js:198
}).run();
^
错误:无法在noYieldsAllowed块中调用yield!
在Function.Fiber.yield(packages/meteor/Fiber\u helpers.js:11)
在Function.wait(home/yaakov/.meteor/tools/cef2bcd356/lib/node_modules/fibers/future.js:111:14)
在Object.Future.wait(/home/yaakov/.meteor/tools/cef2bcd356/lib/node_modules/fibers/Future.js:325:10)
在新的MongoConnection上(packages/mongo-livedata/mongo_-driver.js:196)
在新的MongoInternals.RemoteCollectionDriver(packages/mongo-livedata/remote\u-collection\u-driver.js:4)
反对。(packages/mongolivedata/remote_collection_driver.js:44)
在Object.defaultRemoteCollectionDriver(packages/underline/underline.js:750)
在newMeteor.Collection(packages/mongolivedata/Collection.js:72)
在app/Bug.js:4:17
在packages/deps/deps.js:47

我做错了什么?如何在meteor服务器上创建反应式收集查询?

Deps包仅在客户端工作,因此不能在服务器上使用
Deps.autorun

要在服务器上使用反应式查询,请改为使用
observe

var items=collection.find().observe({
    added: function (document) {
        // ...
    },
    changed: function (newDocument, oldDocument) {
        // ...
    },
    removed: function (oldDocument) {
        // ...
    }
});