MongoDB Query Service
The MongoDB Query Service allows to execute MongoDB aggregation queries against the processed data of a project. Furthermore, some additional features, like storing query templates or providing on overview of the query history, are offered. A project can have more than one collection for processed data, hence the target collection needs to be given as well when executing queries.
We recommend you to use preemptive authentication. That way, the basic authentication request is sent before the server returns an unauthorized response. Also refer to the Apache documentation.
Table of contents
MongoDB Query Service - base URL
Example for synchronous query execution
The example below shows a HTTP POST request for executing a MongoDB aggregation query against a demo collection. Please note that this is a synchronous call which returns the query result immediately. This might lead to HTTP timeouts if the query takes too long. The authentication header is additionally shown for the example credentials of foo:bar.
HTTP POST https:
//bosch-iot-insights.com/mongodb-query-service/v2/queries
Header:
Content-Type: application/json
Accept: application/json
Authorization: Basic Zm9vOmJhcg==
Body:
{
"aggregate"
: [
{
"$limit"
:
10
}
],
"collection"
:
"demo_processed_data"
}
Example for asynchronous query execution
The example below shows a HTTP POST request for executing a MongoDB aggregation query asynchronous. This is required for long running queries (> 10 seconds) to not run into a HTTP timeout. The authentication header is additionally shown for the example credentials of foo:bar.
HTTP POST https:
//bosch-iot-insights.com/mongodb-query-service/v2/queries
Header:
Content-Type: application/json
Accept: application/json
Authorization: Basic Zm9vOmJhcg==
Body:
{
"aggregate"
: [
{
"$limit"
:
10
}
],
"collection"
:
"demo_processed_data"
,
"async"
:
true
}
The resulting document shows the query status, which is "PENDING" at first.
{
"id"
:
"59b78c8e32501c0015c28b5a"
,
"requestType"
:
"ASYNC"
,
"collection"
:
"demo_processed_data"
,
"type"
:
"AGGREGATE"
,
"query"
: [
{
"$limit"
:
1
}
],
"createdAt"
:
"2017-09-12T07:28:14Z"
,
"status"
:
"PENDING"
}
Use the following request to poll the query status. Replace the id in the URL with the one given from the first response. Poll the status as long as it changes to "SUCCESSFUL".
HTTP GET https:
//bosch-iot-insights.com/mongodb-query-service/v2/queries/{id}
Header:
Accept: application/json
Authorization: Basic Zm9vOmJhcg==
As soon as the query has completed, you can fetch those results using the following request. Again, replace the id in the URL with the one of your query-request.
HTTP GET https:
//bosch-iot-insights.com/mongodb-query-service/v2/queries/{id}/result
Header:
Accept: application/json
Authorization: Basic Zm9vOmJhcg==