MongoDB.live, free & fully virtual. June 9th - 10th. Register Now MongoDB.live, free & fully virtual. June 9th - 10th. Register Now

How do I properly ensure a chunk has been successfully written with GridFS?

On the docs for the write method, it says that the callback is called when the chunk has been added to the buffer or if it was flushed to MongoDB. However, this is not the case for me. Even though the chunk gets successfully written to the fs.chunks collection, the callback does not seem to be called. Am I doing or understanding something wrong? Here is a simple version of my code, I’m basically trying to make the promise resolve when the chunk has been successfully written, or reject if there was an error.

  function _writeStream(chunk) {
    return new Promise((resolve, reject) => {
      uploadStream.write(chunk, (error) => {
        if (error) reject(error);
        else resolve();
      });
    });
  }