Is there a way to remove the quotes from the $regex objects shown below?
{ '$or':
[ '{"last":{"$regex":"/.*Pat.*/"}}',
'{"first":{"$regex":"/.*Pat.*/"}}' ],
thing: 57b713625bf9b85ca824de8c }
I attempted the following approach, but it doesn't work and I believe there must be a more efficient solution because I am unable to figure out how to assign an expression as the value of an object.
for (var key in req.query) {
if (req.query.hasOwnProperty(key)) {
if (key === '$or') {
for (var item in req.query[key]) {
if (req.query[key].hasOwnProperty(item)) {
req.query[key][item] = JSON.parse(req.query[key][item]);
for (var x in req.query[key][item]) {
for (var thereMustBeABetterWayToDoThis in req.query[key][item][x]){
req.query[key][item][x][thereMustBeABetterWayToDoThis] = req.query[key][item][x][thereMustBeABetterWayToDoThis].replace(/["']/g, "");
}
}
}
}
}
}