I tried something similar, and found that Mongo executed the query progressively slower and slower because it apparently has to read each document and covert them into a JavaScript object to execute that query. In 1.4, expression language support is supposed to be added to the query field so there should be no problem using EL to inject a raw timestamp into the query.
Mike On Wed, Sep 6, 2017 at 12:45 PM, faustina Selvadeepa <[email protected]> wrote: > Thanks a ton koji, this worked :) > > Thanks, > Faustina > > On 06-Sep-2017 2:20 PM, "Koji Kawamura" <[email protected]> wrote: > > Hi Faustina, > > It was close, I think you need to add "this" keyword. without that, it > evaluates a literal "Incident Submitted Dt" against dd() return value. > So, it should be like this: > > {"$where": "this[\"Incident Submitted Dt\"] >= dd()"} > > Then dd() return value is compared with each document's 'Incident > Submitted Dt' value. > Tested with MongoDB console. > https://docs.mongodb.com/manual/tutorial/query-documents/ > > Thanks, > Koji > > On Wed, Sep 6, 2017 at 4:06 PM, faustina Selvadeepa > <[email protected]> wrote: > > Hi Koji, > > > > Thanks a lot for your response. > > The above code removed the JsonParseException, but it is fetching all the > > data from the database. It's not executing my function call dd(). Is > there a > > way to make a function call in the same query? > > > > Thanks, > > Faustina > > > > > > On 6 September 2017 at 10:47, Koji Kawamura <[email protected]> > wrote: > >> > >> Hi Faustina, > >> > >> I'm not familiar with MongoDB query syntax, but based on the > >> Stackoverflow answer, to avoid JsonParseException and query a field > >> containing space, something like below may work? i.e. escaping the > >> double quotes > >> > >> {"$where": "\"Incident Submitted Dt\" >= dd()"} > >> > >> > >> Thanks, > >> Koji > >> > >> On Wed, Sep 6, 2017 at 1:18 PM, faustina Selvadeepa > >> <[email protected]> wrote: > >> > Hi, > >> > > >> > I want my getmongo processor to fetch the data of past 2 days only. > So I > >> > referred this link to create a function and call that function from > the > >> > query field in getmongo processor: > >> > > >> > https://stackoverflow.com/questions/44573618/how-to-get-iso- > string-in-nifi-getmongo-query-field/44725438#44725438 > >> > > >> > Function to get a date: > >> > > >> > db.system.js.save({ > >> > > >> > "_id": "dd", > >> > > >> > "value": function() { > >> > > >> > var todayTime = new Date(); > >> > > >> > var yesterday = new Date() > >> > > >> > yesterday.setDate(todayTime.getDate() - 2) > >> > > >> > var month = yesterday.getMonth() + 1; > >> > > >> > var day = yesterday.getDate(); > >> > > >> > var year = yesterday.getFullYear().toString().substr(-2); > >> > > >> > var prev_date=month + "/" + day + "/" + year; > >> > > >> > return prev_date; > >> > > >> > } > >> > > >> > }); > >> > > >> > Query to fetch all the data that is greater than the calculated date: > >> > > >> > {"$where": "Incident Submitted Dt": $gte: dd()} > >> > > >> > I am getting a Json parse exception in the processor: > >> > > >> > 'Query validated against '{"$where": "Incident Submitted Dt": $gte: > >> > dd()}' > >> > is invalid because org.son.json.JsonParseException. > >> > > >> > > >> > I am sure the query is wrong, but I don't know how to write a valid > >> > query. > >> > > >> > > >> > Request you to help!! > >> > > >> > > >> > Thanks, > >> > > >> > Faustina > > > > > > >
