Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Aggregate HTTP Interface

The Learning Locker Aggregate HTTP interface utilises the Mongo aggregation API and is only available for allowed collections. The Aggregate HTTP Interface is more advanced than the xAPI HTTP interface and allows you to access MongoDB's powerful Aggregation API for more custom filtration of documents.

...

When using this interface, you must additionally supply your Basic Auth details with each request in the Authorization header. Your Basic Auth details can be found under Settings > Clients. The interface can be passed options via a JSON object in the request body (described in the table below). The collection property is required. The collection is a string that determines the collection name used to execute the aggregation on. The other properties are optional.

Name

Description

Default Value

pipeline

Array containing a pipeline of stages for documents to pass through before being output from the interface.

[]

(in this case, you'll get records from the desired collection without any transformations)

skip

Number that specifies a number of records that should be skipped from the beginning. This parameter will be transformed into $skip aggregation stage and executed at the very end.

0

limit

Number that specifies a number of records that will be cut from the final results. This parameter will be transformed into $limit aggregation stage and executed at the very end.

10000

maxTimeMS

Number that specifies the time limit for the query in Mongo.

0

(if nothing else was set to MAX_TIME_MS environment variable)

batchSize

Specifies the number of documents to return in each batch of the response from the MongoDB instance. Defaults to 100

100

Example

A simple request to this interface using all of the available parameters looks like the request below.

...

So far we've only seen the limit and project stages, however, there are many other stages available in Mongo. The common stages are listed in the table below.

Name

Description

project

Reshapes the records from the previous stage of the pipeline for the next stage.

match

Filters the records from the previous stage of the pipeline for the next stage.

limit

Limits the number of records from the previous stage of the pipeline for the next stage.

skip

Skips a number of records from the previous stage of the pipeline for the next stage.

group

Groups records by a specified identifier from the previous stage of the pipeline for the next stage.

sort

Sorts the records from the previous stage of the pipeline for the next stage.