Our Community is getting an upgrade! To get everything ready for the relaunch, we’ll be placing the site in read-only mode starting September 21st.
We really appreciate your understanding while we get things set up behind the scenes. Catch up on all the exciting details about the move here.
Need help or have questions? Drop us a line at [email protected]

Support Questions

Find answers, ask questions, and share your expertise
Announcements
Share your experience with Cloudera on G2 and get a $25 Amazon Gift card.
Hi, I'm CLEO! Something exciting is coming to the Community. Stay Tuned!

NiFi RunMongoAggreation - How to get all documents within a time range?

avatar
New Contributor

I am trying to get all documents within a time range using RunMongoAggreation.

In console I tried with below query and it worked fine.

aggregate([
{
"$match": {
"modified_at": {
"$gte": ISODate("2017-02-08T12:10:40.787")
}
}
}
])

Flowfile has below properties

startTimestamp: 2017-02-08T12:10:40.787

Below is the query being used in RunMongoAggreation

[
{
"$match": {
"modified_at": {
"$gte": "${startTimestamp}"
}
}
}
]

Its not return result

1 ACCEPTED SOLUTION

avatar
New Contributor

Im convert match field to timestamp then compare. Resolved

[
    {
        "$addFields": {
            "timestamp": {
                "$toLong": "$modified_at"
            }
        }
    },
    {
        "$match": {
                "timestamp": {
                    "$gte": ${stored.state:toDate("yyyy-MM-dd HH:mm:ss"):toNumber()}
                },
                "timestamp": {
                    "$gte": ${current.state:toDate("yyyy-MM-dd HH:mm:ss"):toNumber()}
                }
         }
    },
    {
        "$skip": ${offset}
    },
    {
        "$limit": ${limit}
    },
    {
        "$project": {
            "code": 1
        }
    }
]

 

View solution in original post

1 REPLY 1

avatar
New Contributor

Im convert match field to timestamp then compare. Resolved

[
    {
        "$addFields": {
            "timestamp": {
                "$toLong": "$modified_at"
            }
        }
    },
    {
        "$match": {
                "timestamp": {
                    "$gte": ${stored.state:toDate("yyyy-MM-dd HH:mm:ss"):toNumber()}
                },
                "timestamp": {
                    "$gte": ${current.state:toDate("yyyy-MM-dd HH:mm:ss"):toNumber()}
                }
         }
    },
    {
        "$skip": ${offset}
    },
    {
        "$limit": ${limit}
    },
    {
        "$project": {
            "code": 1
        }
    }
]