|
db.getCollection('statements').aggregate([ |
|
{ |
|
// newest first |
|
$sort: { |
|
"_id": -1 |
|
} |
|
}, |
|
{ |
|
$project: { |
|
/*statement: 1,*/ |
|
|
|
//// statement, verb, object ids |
|
|
|
statementId: "$statement.id", |
|
verbId: "$statement.verb.id", |
|
activityId: "$statement.object.id", |
|
|
|
//// context activity id's |
|
|
|
// parent |
|
contextActivitiesParent: { |
|
$map: { |
|
input: "$statement.context.contextActivities.parent", |
|
as: "item", |
|
in: { $concat: ["", "$$item.id"] } |
|
} |
|
}, |
|
// grouping |
|
contextActivitiesGrouping: { |
|
$map: { |
|
input: "$statement.context.contextActivities.grouping", |
|
as: "item", |
|
in: { $concat: ["", "$$item.id"] } |
|
} |
|
}, |
|
// category |
|
contextActivitiesCategory: { |
|
$map: { |
|
input: "$statement.context.contextActivities.category", |
|
as: "item", |
|
in: { $concat: ["", "$$item.id"] } |
|
} |
|
}, |
|
// other |
|
contextActivitiesOther: { |
|
$map: { |
|
input: "$statement.context.contextActivities.other", |
|
as: "item", |
|
in: { $concat: ["", "$$item.id"] } |
|
} |
|
} |
|
} |
|
} |
|
]); |
|
|
|
/** |
|
* output example |
|
*/ |
|
|
|
// [{ |
|
// "_id" : ObjectId("59ee87e2785e262fb577c2b7"), |
|
// "statementId" : "d427dbfd-58a1-0ab2-ac25-4dc41bb02c97", |
|
// "verbId" : "https://adlnet.gov/expapi/verbs/experienced", |
|
// "activityId" : "https://mysite.com/lessons/first-lesson", |
|
// "contextActivitiesParent" : [ |
|
// "https://lxhive.com/recipes/wordpress/WP_Post/lessons", |
|
// "https://lxhive.com/recipes/wordpress/WP_Taxonomy/tags" |
|
// ], |
|
// "contextActivitiesGrouping" : [ |
|
// "https://lxhive.com/recipes/wordpress/type/lessons", |
|
// "https://mysite.com/recipes/resource", |
|
// "https://mysite.com/recipes/trigger", |
|
// "https://lxhive.com/recipes/wordpress/plugin/lx-lessons" |
|
// ], |
|
// "contextActivitiesCategory" : [ |
|
// "http://cumulus.brightcookie.com.au/tags/infographic" |
|
// ], |
|
// "contextActivitiesOther" : [ |
|
// "https://mysite.com/wp-admin/admin-ajax.php" |
|
// ] |
|
// }] |
basic lxHive Mongo Cheatsheets