com.mongodb.MongoGridFSException: Could not find file chunk for files_id: BsonObjectId{value=57c87e6afc76010ce8f43887} at chunk index 2.

JIRA | Sean Fitts | 8 months ago
tip
Your exception is missing from the Samebug knowledge base.
Here are the best solutions we found on the Internet.
Click on the to mark the helpful solution and get rewards for you help.
  1. 0

    When using GridFSDownloadStream to download a file with multiple chunks, if you use a destination buffer whose size is not exactly equal to the file's chunk size then you will get the following exception: {noformat} com.mongodb.MongoGridFSException: Could not find file chunk for files_id: BsonObjectId{value=57c87e6afc76010ce8f43887} at chunk index 2. at com.mongodb.async.client.gridfs.GridFSDownloadStreamImpl.chunkNotFound(GridFSDownloadStreamImpl.java:235) at com.mongodb.async.client.gridfs.GridFSDownloadStreamImpl.access$600(GridFSDownloadStreamImpl.java:38) at com.mongodb.async.client.gridfs.GridFSDownloadStreamImpl$5.onResult(GridFSDownloadStreamImpl.java:168) at com.mongodb.async.client.gridfs.GridFSDownloadStreamImpl$5.onResult(GridFSDownloadStreamImpl.java:162) at com.mongodb.operation.AsyncQueryBatchCursor.next(AsyncQueryBatchCursor.java:109) at com.mongodb.async.client.gridfs.GridFSDownloadStreamImpl.checkAndFetchResults(GridFSDownloadStreamImpl.java:162) at com.mongodb.async.client.gridfs.GridFSDownloadStreamImpl.read(GridFSDownloadStreamImpl.java:132) {noformat} I have created a GIST for a JUnit test which demonstrates the issue -- https://gist.github.com/sfitts/6ac8fc6efa19ef86600ae5354682c5ca The issue seems to be that the code decides to do a read-ahead into a chunk that doesn't exist (it is one off the edge) and so doesn't get to use the data already sitting in "buffer" to fulfill the read.

    JIRA | 8 months ago | Sean Fitts
    com.mongodb.MongoGridFSException: Could not find file chunk for files_id: BsonObjectId{value=57c87e6afc76010ce8f43887} at chunk index 2.

    Root Cause Analysis

    1. com.mongodb.MongoGridFSException

      Could not find file chunk for files_id: BsonObjectId{value=57c87e6afc76010ce8f43887} at chunk index 2.

      at com.mongodb.async.client.gridfs.GridFSDownloadStreamImpl.chunkNotFound()
    2. com.mongodb.async
      GridFSDownloadStreamImpl$5.onResult
      1. com.mongodb.async.client.gridfs.GridFSDownloadStreamImpl.chunkNotFound(GridFSDownloadStreamImpl.java:235)
      2. com.mongodb.async.client.gridfs.GridFSDownloadStreamImpl.access$600(GridFSDownloadStreamImpl.java:38)
      3. com.mongodb.async.client.gridfs.GridFSDownloadStreamImpl$5.onResult(GridFSDownloadStreamImpl.java:168)
      4. com.mongodb.async.client.gridfs.GridFSDownloadStreamImpl$5.onResult(GridFSDownloadStreamImpl.java:162)
      4 frames
    3. MongoDB Java Driver
      AsyncQueryBatchCursor.next
      1. com.mongodb.operation.AsyncQueryBatchCursor.next(AsyncQueryBatchCursor.java:109)
      1 frame
    4. com.mongodb.async
      GridFSDownloadStreamImpl.read
      1. com.mongodb.async.client.gridfs.GridFSDownloadStreamImpl.checkAndFetchResults(GridFSDownloadStreamImpl.java:162)
      2. com.mongodb.async.client.gridfs.GridFSDownloadStreamImpl.read(GridFSDownloadStreamImpl.java:132)
      2 frames