You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a project where the user can search his products using a search field. I'm using a Regex to query the products by name. There seems to be a bug for products with the same name. There is only one returned. My helper function looks like this :
products : function(){
var query = Session.get('productsList.query');
if(!query || query.length < 2)
return Products.find();
var regex = new RegExp(query, 'gi');
return Products.find({name : {$regex : regex}});
},
I believe you intended to either query { name: regex } or { name: { $regex: query } }. I am not completely sure what should happen when you ask to take a regex as an argument for $regex operator.
After stepping through the minimongo code with a debugger, it looks like you get this behavior because of the g flag in your regexp. The global flag tells regexp to keep a state so when called on the same string, the regexp should start from the position it finished last time (in this case "Shorts" and "Shorts" is the same string in JS terminology).
Hello,
I have a project where the user can search his products using a search field. I'm using a
Regex
to query the products by name. There seems to be a bug for products with the same name. There is only one returned. My helper function looks like this :Here is the reproduction info :
I tried using the full name without the regex and it returns all the corresponding products. Also, the regex works fine in MongoDB.
The text was updated successfully, but these errors were encountered: