I am trying to do a case-insensitive search using Regex - the documentation gives examples with literal strings but I am trying this using a variable instead. This search works but only with matching case - how can I make it case insensitive?
I get no error now, but the result of the find is always blank with either syntax. Even if I replace param1 with the desired parameter in quotes the find is always blank.
However this more simplified version does work - but only as a case-sensitive search:
return mycollection.find ({"dt_name":param1});
How do I get it to work not as a case-sensitive search?
I’m not 100% sure why that’s not working for you because It works for me.
What is the value of param1 look like?
Try to make a loop to log each doc after before return see what is the output.
Something like:
data = mycollection.find ({"dt_name": { '$regex' : new RegExp("Kaplan", "i").toString()} });
// or
// data = mycollection.find ({"dt_name": { '$regex' : 'Kaplan', "$options": "i" } });
for (const d of data) {
console.log(d);
}
return data
Hi! I’ve been trying to make it works with RegExp on Realm but have not solved it yet.
It seems like the the slashes when convert a RegExp object to string is the problem.
e.g
This won’t work
let pattern = new RegExp("abc").toString()
console.log(pattern);
"/abc/"