epileptic
epileptic

Reputation: 25

meteor autocomplete server-side

I'm writing a meteor app and I'm trying to add an autocomplete feature to a search box. The data is very large and is on the server, so I can't have it all on the client. It's basically a database of users. If I'm not wrong, the mizzao:autocomplete package should make that possible, but I can't seem to get it to work.

Here's what I have on the server:

Meteor.publish('autocompleteViewers', function(selector, options) {
  Autocomplete.publishCursor(viewers.find(selector, options), this);
  this.ready();
});

And here are the settings I use for the search box on the client:

  getSettings: function() {
    return {
      position: 'bottom',
      limit: 5,
      rules: [{
        subscription: 'autocompleteViewers',
        field: '_id',
        matchAll: false,
        options: '',
        template: Template.vLegend
      }],
    };
  }

But I keep getting this error on the client:

Error: Collection name must be specified as string for server-side search at validateRule

I don't really understand the problem. When I look at the package code, it just seems like it's testing whether the subscription field is a string and not a variable, which it is. Any idea what the problem could be? Otherwise is there a minimum working example I could go from somewhere? I couldn't find one in the docs.

Upvotes: 1

Views: 256

Answers (1)

Vasyl Semilyak
Vasyl Semilyak

Reputation: 26

Error: Collection name must be specified as string for server-side search at validateRule

You get this error because you don't specify a Collection name in quotes.

getSettings: function() {
 return {
   position: 'bottom',
   limit: 5,
   rules: [{
     subscription: 'autocompleteViewers',
     field: '_id',
     matchAll: false,
     collection: 'viewers', // <- specify your collection, in your case it is a "viewers" collection.
     options: '',
     template: Template.vLegend
   }],
 };

}

For more information please read here.

Hope this helps!

Upvotes: 1

Related Questions