Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 51 additions & 14 deletions lib/storage/metadata/mongoclient/MongoClientInterface.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,25 +250,62 @@ class MongoClientInterface {
}

getBucketAndObject(bucketName, objName, params, log, cb) {
this.getBucketAttributes(bucketName, log, (err, bucket) => {
if (params && params.versionId) {
// eslint-disable-next-line
objName = formatVersionKey(objName, params.versionId);
}
const m = this.getCollection(METASTORE);
m.aggregate([
{ $match: { _id: bucketName } },
{
$lookup: {
from: bucketName,
pipeline: [
{ $match: { _id: objName } },
],
as: 'object',
},
},
], {}, (err, cursor) => {
if (err) {
log.error(
'getBucketAttributes: error getting bucket attributes',
'getBucketAndObject: error getting bucket attributes',
{ error: err.message });
return cb(err);
return cb(errors.InternalError);
}
this.getObject(bucketName, objName, params, log, (err, obj) => {
if (err) {
if (err === errors.NoSuchKey) {
return cb(null,
{ bucket:
BucketInfo.fromObj(bucket).serialize(),
});
}
log.error('getObject: error getting object',
{ error: err.message });
return cb(err);
if (!cursor) {
return cb(errors.NoSuchBucket);
}
cursor.on('data', doc => {
// FIXME: there should be a version of BucketInfo.deserialize()
// that properly inits w/o JSON.parse()
const bucketMDStr = JSON.stringify(doc.value);
const bucket = BucketInfo.deSerialize(bucketMDStr);

if (doc.object.length === 0) {
return cb(null,
{ bucket:
BucketInfo.fromObj(bucket).serialize(),
});
}
const obj = doc.object[0].value;
if (obj.isPHD) {
const c = this.getCollection(bucketName);
this.getLatestVersion(c, objName, log, (err, obj) => {
if (err) {
log.error(
'getLatestVersion: getting latest version',
{ error: err.message });
return cb(err);
}
return cb(null, {
bucket: BucketInfo.fromObj(bucket).serialize(),
obj: JSON.stringify(obj),
});
});
return undefined;
}
MongoUtils.unserialize(obj);
return cb(null, {
bucket: BucketInfo.fromObj(bucket).serialize(),
obj: JSON.stringify(obj),
Expand Down