Created
June 28, 2018 18:33
-
-
Save mushinlogit/41bcfa4d54d5a2bf323e5040dfeda350 to your computer and use it in GitHub Desktop.
published.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.getCollection('stix').aggregate([ | |
{ $match: { 'stix.type': 'x-unfetter-assessment-set' } }, | |
{ | |
$project: { | |
'stix.assessment_sets': { | |
$arrayElemAt: ['$stix.assessment_sets', 0] | |
}, | |
'metaProperties.published': 1, | |
'stix.id': 1, | |
'stix.name': 1, | |
'stix.modified': 1, | |
'stix.created_by_ref': 1, | |
creator: 1 | |
} | |
}, | |
{ | |
$group: { | |
_id: '$stix.id', | |
id: { | |
$push: '$stix.id' | |
}, | |
published: { | |
$first: '$metaProperties.published' | |
}, | |
name: { | |
$first: '$stix.name' | |
}, | |
modified: { | |
$max: '$stix.modified' | |
}, | |
creator: { | |
$first: '$creator' | |
}, | |
created_by_ref: { | |
$first: '$stix.created_by_ref' | |
}, | |
stix: { | |
$addToSet: { | |
type: '$stix.assessment_sets.stix.type', | |
id: '$stix.id' | |
} | |
} | |
} | |
}, | |
{ | |
$unwind: '$stix' | |
}, | |
{ | |
$sort: { | |
modified: -1 | |
} | |
} | |
]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment