Error querying GridFS

81 views
Skip to first unread message

Mrityunjay

unread,
Apr 30, 2012, 1:38:19 AM4/30/12
to mongodb-ca...@googlegroups.com
I'm calling the following to query a file from GridFS:

    val gridfs = GridFS(DB, "photos")
    val file = gridfs.findOne(fileName)   //errors out here

However, the code above seems randomly to throw the following exception:

Apr 30, 2012 5:10:27 AM com.mongodb.DBTCPConnector$MyPort error
SEVERE: MyPort.error called
java.lang.ClassCastException: org.joda.time.DateTime cannot be cast to java.util.Date
    at com.mongodb.gridfs.GridFSFile.put(GridFSFile.java:185)
    at org.bson.BasicBSONCallback._put(BasicBSONCallback.java:154)
    at org.bson.BasicBSONCallback.gotDate(BasicBSONCallback.java:110)
    at org.bson.BSONDecoder.decodeElement(BSONDecoder.java:156)
    at org.bson.BSONDecoder._decode(BSONDecoder.java:63)
    at org.bson.BSONDecoder.decode(BSONDecoder.java:42)
    at com.mongodb.Response.<init>(Response.java:63)
    at com.mongodb.DBPort.go(DBPort.java:110)
    at com.mongodb.DBPort.go(DBPort.java:75)
    at com.mongodb.DBPort.call(DBPort.java:65)
    at com.mongodb.DBTCPConnector.call(DBTCPConnector.java:201)
    at com.mongodb.DBApiLayer$MyCollection.__find(DBApiLayer.java:295)
    at com.mongodb.DBCollection.findOne(DBCollection.java:558)
    at com.mongodb.DBCollection.findOne(DBCollection.java:547)
    at com.mongodb.gridfs.GridFS.findOne(GridFS.java:144)
    at com.mongodb.gridfs.GridFS.findOne(GridFS.java:136)
    at com.mongodb.casbah.gridfs.GridFS$$anonfun$findOne$3.apply(GridFS.scala:215)
    at com.mongodb.casbah.gridfs.GridFS$$anonfun$findOne$3.apply(GridFS.scala:215)
    at com.mongodb.casbah.gridfs.GridFS.sansJodaTime(GridFS.scala:183)
    at com.mongodb.casbah.gridfs.GridFS.findOne(GridFS.scala:214)
    at ...  <code line pasted above>
   


It seems that Casbah is writing in JodaDateTime to GridFS file collection but on retrieval it is trying to cast it to java.util.Date. Now why this happens only randomly is still eluding me, perhaps it could be because of the sansJodaTime hack in casbah? Any help on this will be appreciated, this is holding up our whole testing.

Regards,
Mrityunjay

Brendan W. McAdams

unread,
Apr 30, 2012, 10:20:18 AM4/30/12
to mongodb-ca...@googlegroups.com
As noted in the documentation, GridFS is currently incompatible with
the registration of custom date objects.

Mrityunjay

unread,
Apr 30, 2012, 10:57:43 PM4/30/12
to mongodb-ca...@googlegroups.com
But we're not using any custom date objects here. If you check the stack trace the error comes up when reading uploadDate field of files collection in GridFS which is not supplied by us, it is auto updated with a date on saving a file.


On Monday, April 30, 2012 7:50:18 PM UTC+5:30, Brendan W. McAdams wrote:
As noted in the documentation, GridFS is currently incompatible with
the registration of custom date objects.


Brendan W. McAdams

unread,
Apr 30, 2012, 11:00:27 PM4/30/12
to mongodb-ca...@googlegroups.com
You are using the Joda DateTime serializers… those are incompatible with GridFS.
Reply all
Reply to author
Forward
0 new messages