Skip to content

Instantly share code, notes, and snippets.

@mushinlogit
Created June 28, 2018 18:33
Show Gist options
  • Save mushinlogit/41bcfa4d54d5a2bf323e5040dfeda350 to your computer and use it in GitHub Desktop.
Save mushinlogit/41bcfa4d54d5a2bf323e5040dfeda350 to your computer and use it in GitHub Desktop.
published.js
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