Skip to content

Commit

Permalink
Modify query to use index.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jack Sheriff committed Sep 14, 2023
1 parent c867272 commit 1c659b0
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/services/relationships-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' } });
}

Expand Down

0 comments on commit 1c659b0

Please sign in to comment.