I want to get the documents in mongodb for the day. I tried querying with mongo compass the code works. The code is as follows:
{
"time_created": {
"$gte": new Date(new Date().setHours(0, 0, 0, 0)),
"$lt": new Date(new Date().setHours(23, 59, 59, 999))
}
}
But when I use the above query code with the "query" property of GetMongo, I get the following error message:
Verification Results
Perform Validation
Component is invalid: 'Query' validated against '{ "time_created": { "$gte": new Date(new Date().setHours(0, 0, 0, 0)), "$lt": new Date(new Date().setHours(23, 59, 59, 999)) } }' is invalid because Query is not a valid JSON representation due to Unrecognized token 'new': was expecting (JSON String, Number, Array, Object or token 'null', 'true' or 'false') at [Source: (String)"{ "time_created": { "$gte": new Date(new Date().setHours(0, 0, 0, 0)), "$lt": new Date(new Date().setHours(23, 59, 59, 999)) } }"; line: 3, column: 16]
I tried converting to JSON format but it doesn't work:
{
"time_created": {
"$gte": { "$date": "${now():format('yyyy-MM-dd\'T\'HH:mm:ss.SSS\'Z\'')}" },
"$lt": { "$date": "${now():format('yyyy-MM-dd\'T\'23:59:59.999\'Z\'')}" }
}
}
and
{
"time_created": {
"$gte": "${now():toDate():format('yyyy-MM-dd\'T\'HH:mm:ss.SSS\'Z\'')}",
}
}
but it not work.
Please help me, thanks.
Can you help me convert mongodb query to json format working with GetMongo ?
{
"time_created": {
"$gte": new Date(new Date().setHours(0, 0, 0, 0)),
"$lt": new Date(new Date().setHours(23, 59, 59, 999))
}
}
Give me another more suitable solution ?
Please help me, thanks.
I fixed it. Nifi's getMongo Query field doesnt support EL. So i created a stored function in MongoDB for my dynamic query and called it from Nifi.
Create function in Mongodb:
Query Nifi:
It is worked!