meteor-autocomplete icon indicating copy to clipboard operation
meteor-autocomplete copied to clipboard

Issue with selector with regex in return

Open shrop opened this issue 9 years ago • 3 comments

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?

shrop avatar Mar 29 '15 23:03 shrop

Were you able to workaround to this?

ankitv89 avatar Dec 16 '16 08:12 ankitv89

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.

mizzao avatar Dec 16 '16 17:12 mizzao

@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!

ankitv89 avatar Dec 16 '16 17:12 ankitv89