Almog
Almog

Reputation: 2837

Meteor Easy Search Package Custom Mongo Selector Query

I'm using the following package in my project - https://github.com/matteodem/meteor-easy-search

Has anyone used it and was able to set custom mongo selectors for the query parameter? The leaderboard example isn't very clear to me. I need to be able to pass meteor user id to:

EasySearch.createSearchIndex('producers', {
    'collection': Producers,
    'field': ['name', 'producerIdNumber', 'blocksCount', 'totalHectares', 'totalArea'],
    'limit': 8,
    'use' : 'mongo-db',
    'sort': function() {
        return { 'created': -1, 'name': -1 };
    },
    'query': function() {
        var selector =  {};
        return  selector
    }
});

How can pass or get the meteor user id? EasySearch.createSearchIndex function runs on both server and client.

Upvotes: 0

Views: 640

Answers (2)

Almog
Almog

Reputation: 2837

I was able to do this like so

'query': function(searchString, opts) {
        // Default query that will be used for the mongo-db selector
        var query = EasySearch.getSearcher(this.use).defaultQuery(this, searchString);

        if (this.props.formName != '') {
            query.formName = this.props.formName;
        }

        if (this.props.producerId != '') {
            query.producerId = this.props.producerId;
        }

        if (this.props.blockUnitCodeSubCode != '') {
            query.blockUnitCodeSubCode = this.props.blockUnitCodeSubCode;
        }

        if (this.props.created.length != 0) {
            query.created = {$gte:new Date(this.props.created[0]), $lt:new Date(this.props.created[1])};
        } 

Upvotes: 0

Kyle Butler
Kyle Butler

Reputation: 13

I don't have the answer to your problem - but I may be able to point you in the right direction. If you are using the meteor-accounts package, and you need to pull the user ID out of the Meteor.users() collection - you first have to publish your users.

On the server-code ->

Meteor.publish(null, function() {
  return Meteor.users.find({}, {
    fields: {
      username: 1,
      profile: 1
    }
  });
});

on the client, you should be able to return Meteor.users.find() or findOne() to get a userId. not the complete answer but may help?

Upvotes: 1

Related Questions