Skip to main content
Announcements
A fresh, new look for the Data Integration & Quality forums and navigation! Read more about what's changed.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

How to Query MongoDB on a Date Column in Talend Big Data?

Hi,
Lets say I insert a date into MongoDB using tMongoDBConnection-->tFixedFlowInput-->tMongoDBOutput, using TalendDate.parseDate("yyyy-MM-dd","2014-01-01").
I can go into the Mongo shell, and query the collection:
0683p000009MAxG.png
I can see that the record has been inserted using ISODate.
In the shell I would query it like this ( {dt:ISODate("2014-01-01T08:00:00Z")} ) :
0683p000009MB8r.png
However, if I write the identical query in tMongoDBInput:

0683p000009MB6X.png
I receive the following error:
Exception in component tMongoDBInput_1
com.mongodb.util.JSONParseException:
{'dt':ISODate('2014-01-01T08:00:00Z')}
      ^
    at com.mongodb.util.JSONParser.parse(JSON.java:198)
    at com.mongodb.util.JSONParser.parseObject(JSON.java:231)
    at com.mongodb.util.JSONParser.parse(JSON.java:195)
    at com.mongodb.util.JSONParser.parse(JSON.java:145)
    at com.mongodb.util.JSON.parse(JSON.java:81)
    at com.mongodb.util.JSON.parse(JSON.java:66)
    at primehome.testmongodate_0_1.TestMongoDate.tMongoDBInput_1Process(TestMongoDate.java:605)
    at primehome.testmongodate_0_1.TestMongoDate.tMongoDBConnection_1Process(TestMongoDate.java:371)
    at primehome.testmongodate_0_1.TestMongoDate.runJobInTOS(TestMongoDate.java:989)
    at primehome.testmongodate_0_1.TestMongoDate.main(TestMongoDate.java:854)
This question has been asked on the Talend Forum https://community.talend.com/t5/Design-and-Development/tMongoDBInput-query-for-date-gte/td-p/85560 but I was unable to get the answer, which said to query using the "$date" operation, to work.
In the Mongo Shell, I cannot use the query {'dt': {'$date':'2014-01-01T08:00:00Z'}} without the following error:

0683p000009MB8w.png"Can't canonicalize query: BadValue unknown operator: $date".
In the mongoshell, If I do a query like {dt: {$lte : {$date : '2020-01-01T00:00:00Z'}}} I receive no error, but I also receive no document:
0683p000009MB91.png
Is there a way to query MongoDB for dates in Talend?
Regards,
Matthew
Labels (4)
3 Replies
Anonymous
Not applicable
Author

Perhaps the MongoDB driver works a bit different as the shell. Why do you quote the attribute name? Actually this is not necessary and I guess this is the problem.
krengan21
Creator

How to get the previous date data from mongodb using talend i am also getting the same error in tmongodbinput component
Anonymous
Not applicable
Author

You have to set the attribute names and string values in double quotes like this:
"{\"id\":\"my_value\"}"