Meteor-Community-Packages / meteor-autocomplete

Client/server autocompletion designed for Meteor's collections and reactivity.
https://atmospherejs.com/mizzao/autocomplete
MIT License
350 stars 109 forks source link

Issue with selector with regex in return #81

Open shrop opened 9 years ago

shrop commented 9 years ago

I have seen a few examples like below:

selector: function(match) {
  regex = new RegExp(match, 'i')
  return {'profile.firstName': regex}
}

I am actually trying the code above. If I put a string in place of regex, it is passed and works correctly, but when I use the regex variable, the output sent to query looks like this 'profile.firstName': {} } { limit: 10, sort: { _id: 1 } }. Notice the regex portion is missing.

Anyway, I am not sure why this doesn't work yet. Any thoughts?

ankitv89 commented 7 years ago

Were you able to workaround to this?

mizzao commented 7 years ago

I don't think you can use a Javascript regex in a Mongo query that way; you should try the string literal version: https://docs.mongodb.com/manual/reference/operator/query/regex/ . Otherwise, use $regex.

ankitv89 commented 7 years ago

@mizzao Yes. I did the same. Will share the code in some time to help others who face this issue.

Thanks for responding and making this great package!