Reputation: 225
I am writing a Meteor method that searches all of my collections for keywords. One stumbling point I am having is how to manipulate/concat returned cursors like arrays. Is it best to turn them into arrays concat and manipulate them from there, or is there a way to concat/manipulate cursors?
Thanks for all the help!
Upvotes: 1
Views: 219
Reputation: 1850
I think you want to use
var array = [];
cursor.map(function( element ){
//test element for keyword
if( isKeyword( element ) ){
//add stuff to array
array.push( element );
}
});
Manipulation of a cursor makes no sense so you have to bring your own array to store the found data.
But what is this cursor? It is a mongo cursor and is defined 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.
More information here.
Upvotes: 0
Reputation: 7139
A cursor can't be concatenated because a cursor is not a data structure, it is a data accessor.
It just says how to access data.
If you need to concatenate cursors, you can either store the data in a new collection/change a publication to aggregate, or you can fetch
them and concatenate the resulting arrays.
Upvotes: 1