I am trying to create a mongoDB query but the conditional is set as a string and the output is returning a blank array. Here is an example of what I'm tyring to do:
let sample_text = "{$and: [some conditions]}"
let results = My_Collection.find(sample_text).fetch()
This will result in a an empty array. But if I manually enter the regex query like this I get an array with the values I'm expecting:
let results = My_Collection.find({$and: [some conditions]}).fetch()
The sampe text regex string is being generated by an outside funciton and is being returned as a string.
My question is how can I insert my regex string without the quotations? Or is there a better way to generate the regex without making it a string in the first place?
I have tried using new RegExp but that destroys some of my expressions, and I have tried to simply remove the quotations as the first and last character but that doesn't work either.
Edit: Cannot simply turn query into a JSON object since it contains special characters such as $.