Travis
01/04/2024, 4:08 AMjavacast can fix.
Examples: a string value true is automatically type cast as boolean, a string value 12-1 is suddenly a date, so is 35258-7 oddly.
Most times it's not noticeable until you start interacting with MongoDB.Travis
01/04/2024, 4:57 AMAdam Cameron
Yogesh Lucid
01/04/2024, 12:05 PMdswitzer
01/04/2024, 1:42 PMTravis
01/04/2024, 3:14 PMarrayAppend(loc.criteria['$or'],{"#loc.sField#": { '$regex': trim(sData), '$options':'mi'} }, true);
where sData = "true"
JavaCast helps nothing in this case.
Good point that it could very well be the driver though.Adam Cameron
loc.criteria['$or'] = [];
loc.sField = "someProperty";
sData = "true";
bData = true;
arrayAppend(
loc.criteria['$or'],
{
"#loc.sField#": {
'$regex': trim(sData), // "true"
'$options':'mi',
"bData": bData // true
}
},
true
);
writeOutput(serializeJson(loc.criteria['$or']));
And this works exactly as I'd expect on CF2018+ and Lucee 5+:
[{"someProperty":{"$options":"mi","bData":true,"$regex":"true"}}]
"true" is still "true" and true is still true.
What are you seeing? Or how do your expectations diverge from what it does?Travis
01/04/2024, 3:41 PMAdam Cameron
dswitzer
01/04/2024, 3:44 PMarrayAppend(loc.criteria['$or'],{"#loc.sField#": { '$regex': trim(sData), '$options':'mi'} }, true);
The use of trim() is going to make sData a string.dswitzer
01/04/2024, 3:45 PMarrayAppend(loc.criteria['$or'],{"#loc.sField#": { '$regex': javaCast("boolean", trim(sData)), '$options':'mi'} }, true);
(If you don't actually need the trim() just remove it)Travis
01/04/2024, 3:46 PMdswitzer
01/04/2024, 3:48 PMTravis
01/04/2024, 3:51 PMdswitzer
01/04/2024, 3:51 PMdswitzer
01/04/2024, 3:51 PMTravis
01/04/2024, 3:52 PMdswitzer
01/04/2024, 3:53 PM"^true$" so it matches the exact value or \btrue\b if you're trying to match the word "true".
Changing the expression above should prevent the value from being converted to a boolean.dswitzer
01/04/2024, 3:54 PM$text search would be more efficient (or some other command other than a regex for this use case)Travis
01/04/2024, 3:54 PMTravis
01/04/2024, 3:54 PMTravis
01/04/2024, 3:58 PM