I'm guessing that you are trying to use Java or MEL syntax in Mule 4 to construct the JSON that is used for the MongoDB query. In Mule 4 you need to use DataWeave as the expression language. An expression in DataWeave to generate something similar could be:
%dw 2.0
output application/json
---
{
"createdAt" : {
"\$gte": (now() - |P1D|) as String { format: "yyyy-MM-dd'T'hh:mm:ss'Z'"}
}
}
Output:
{
"createdAt": {
"$gte": "2022-10-18T12:06:19Z"
}
}
If you need a different date time format you can tinker with the format in the expression.
Note that DataWeave supports date arithmetic with periods of time so you don't need to use hacks like subtracting a number of milliseconds. |P1D|
is a period of 1 day.