操纵 Meteor 游标

Manipulating Meteor cursors

我正在编写一个 Meteor 方法,用于在我的所有集合中搜索关键字。我遇到的一个绊脚石是如何 manipulate/concat 像数组一样返回游标。最好将它们变成数组 concat 并从那里操作它们,还是有办法 concat/manipulate 游标?

感谢大家的帮助!

无法连接游标,因为游标不是数据结构,它是数据访问器。
它只是说 如何 访问数据。

如果您需要连接游标,您可以将数据存储在新的 collection/change 发布中进行聚合,或者您可以 fetch 它们并连接结果数组。

我想你想用

var array = [];
cursor.map(function( element ){
  //test element for keyword       
  if( isKeyword( element ) ){
    //add stuff to array
    array.push( element );
  }
});

Doc for map

游标的操作毫无意义,因此您必须使用自己的数组来存储找到的数据。

但是这个光标是什么?它是一个 mongo 游标,定义为 here:

A pointer to the result set of a query. Clients can iterate through a cursor to retrieve results. By default, cursors timeout after 10 minutes of inactivity.

更多信息here