diff --git a/lib/attachments/gridstore-storage.js b/lib/attachments/gridstore-storage.js index 2bb87f62..fa0be0ff 100644 --- a/lib/attachments/gridstore-storage.js +++ b/lib/attachments/gridstore-storage.js @@ -142,19 +142,21 @@ class GridstoreStorage { if (args.length > 2) { const calculatedFileContentHash = args[2]; - this.gridfs.collection(this.bucketName + '.files').findOneAndUpdate( - { - _id: hash - }, - { - $set: { - 'metadata.fileContentHash': calculatedFileContentHash + if (calculatedFileContentHash) { + this.gridfs.collection(this.bucketName + '.files').findOneAndUpdate( + { + _id: hash + }, + { + $set: { + 'metadata.fileContentHash': calculatedFileContentHash + } + }, + { + returnDocument: 'after' } - }, - { - returnDocument: 'after' - } - ); + ); + } } callback(...args); });