diff --git a/app/services/relationships-service.js b/app/services/relationships-service.js index fbcfe70e..68eb0a10 100644 --- a/app/services/relationships-service.js +++ b/app/services/relationships-service.js @@ -68,8 +68,8 @@ exports.retrieveAll = async function(options) { if (options.versions === 'latest') { // - Group the documents by stix.id, sorted by stix.modified // - Use the last document in each group (according to the value of stix.modified) - aggregation.push({ $sort: { 'stix.id': 1, 'stix.modified': 1 } }); - aggregation.push({ $group: { _id: '$stix.id', document: { $last: '$$ROOT' } } }); + aggregation.push({ $sort: { 'stix.id': 1, 'stix.modified': -1 } }); + aggregation.push({ $group: { _id: '$stix.id', document: { $first: '$$ROOT' } } }); aggregation.push({ $replaceRoot: { newRoot: '$document' } }); }