diff --git a/lib/storage/metadata/MetadataWrapper.js b/lib/storage/metadata/MetadataWrapper.js index 446c0fd14..7a1422c64 100644 --- a/lib/storage/metadata/MetadataWrapper.js +++ b/lib/storage/metadata/MetadataWrapper.js @@ -255,6 +255,20 @@ class MetadataWrapper { }); } + updateObjectMD(bucketName, objName, objVersion, update, params, log, cb) { + log.debug('updating object in metadata'); + this.client.updateObject(bucketName, objName, objVersion, update, params, log, + err => { + if (err) { + log.debug('error from metadata', { implName: this.implName, + error: err }); + return cb(err); + } + log.debug('object successfully updated in metadata'); + return cb(); + }); + } + putObjectMD(bucketName, objName, objVal, params, log, cb) { log.debug('putting object in metadata'); const value = typeof objVal.getValue === 'function' ? diff --git a/lib/storage/metadata/mongoclient/MongoClientInterface.js b/lib/storage/metadata/mongoclient/MongoClientInterface.js index 2ab6256e8..bfedee407 100644 --- a/lib/storage/metadata/mongoclient/MongoClientInterface.js +++ b/lib/storage/metadata/mongoclient/MongoClientInterface.js @@ -1043,6 +1043,27 @@ class MongoClientInterface { return this.putObjectNoVer; } + updateObject(bucketName, objName, versionId, updateOp, params, log, cb) { + const c = this.getCollection(bucketName); + const filter = { + _id: null, + }; + const update = { + $set: updateOp, + }; + if (versionId) { + const versionKey = formatVersionKey(objName, versionId, params.vFormat); + filter._id = versionKey; + } else { + const key = formatMasterKey(objName, params.vFormat); + filter._id = key; + } + return c.updateOne(filter, update).then(() => cb()).catch(err => { + log.error('updateObject: error updating object', { error: err.message }); + return cb(errors.InternalError); + }); + } + /** * puts object metadata in bucket * @param {String} bucketName bucket name