[Hadoop Mongo Connector] : store datetime from PIG to MongoDB

50 views
Skip to first unread message

Nicolas

unread,
Sep 23, 2015, 11:37:15 AM9/23/15
to mongodb-user
Hello,
We need to store Datetime fields inside MongoDB collection from our PIG script.

If we try for example to send to mongoDB the following query (where $createdAt is result of CurrentTime() function) :

{\$setOnInsert: {  type : "TEST", createdAt : "\$createdAt"},...

we receive the following exception:
Caused by: java.lang.IllegalArgumentException: can't serialize class org.joda.time.DateTime
        at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:273)
        at org.bson.BasicBSONEncoder.putObject(BasicBSONEncoder.java:174)

We receive also an exception in case we try with "new Date()"
Could you help me to solve it ?
Tks
Nicolas

Luke Lovett

unread,
Sep 24, 2015, 4:52:59 PM9/24/15
to mongodb-user
Hi Nicolas,

I think this might be a bug in the Hadoop connector. Would you mind creating an issue on the HADOOP project here? : https://jira.mongodb.org/browse/HADOOP (big green "create" button on the top).

I'm unclear on the exact expected behavior, though, since Pig doesn't have a native "datetime" type. I think at least getting a string representation of the time should be possible, but it might also be possible to store datetimes in MongoDB if the input type happens to be a org.joda.time.DateTime.

Luke Lovett

unread,
Apr 15, 2016, 2:23:28 PM4/15/16
to mongodb-user
I realize this post is pretty old, but I came across it again while searching for something else.

To update this for future visitors: datetimes are now supported in Pig with the Hadoop connector as of version 1.5.0.
Reply all
Reply to author
Forward
0 new messages