Java driver: gridfs without filename

22 views
Skip to first unread message

guillou...@gmail.com

unread,
Jun 21, 2017, 6:00:41 PM6/21/17
to mongodb-user
Hi all,

I am trying to download a file from GridFS using MongoDB Java Driver 3.4.
I know the ID of the file, so I simply do:

  GridFSBucket gridFSFilesBucket = GridFSBuckets.create(db);
  GridFSFile file = gridFSFilesBucket.find(eq("_id", fileId)).first();

But it throws the exception:
Exception in thread "main" org.bson.BsonInvalidOperationException: Document does not contain key filename
at org.bson.BsonDocument.throwIfKeyAbsent(BsonDocument.java:844)
at org.bson.BsonDocument.getString(BsonDocument.java:233)
at com.mongodb.client.gridfs.codecs.GridFSFileCodec.decode(GridFSFileCodec.java:68)
at com.mongodb.client.gridfs.codecs.GridFSFileCodec.decode(GridFSFileCodec.java:48)
at com.mongodb.operation.CommandResultArrayCodec.decode(CommandResultArrayCodec.java:52)

Which is true, as my file does not have a filename, which from the documentation is totally valid: the filename is optional https://docs.mongodb.com/manual/core/gridfs/ 

I encounter the same issue if I try to use downloadToStream.

Is it a bug in the API ?

Cheers,

Kevin Adistambha

unread,
Jun 26, 2017, 1:04:18 AM6/26/17
to mongodb-user

Hi

my file does not have a filename, which from the documentation is totally valid: the filename is optional https://docs.mongodb.com/manual/core/gridfs/
I encounter the same issue if I try to use downloadToStream.

Apparently you are correct. I have submitted JAVA-2546 to seek clarification on this issue. Thanks for bringing this to our attention. Please feel free to watch/upvote/comment on the ticket.

Best regards,
Kevin

Reply all
Reply to author
Forward
0 new messages