younifyd
Menu

Firestore.projects.databases.documents.run Aggregation Query

Runs an aggregation query. Rather than producing Document results like Firestore.RunQuery, this API allows running an aggregation to produce a series of AggregationResult server-side. High-Level Example: ``` -- Return the number of documents in table given a filter. SELECT COUNT(*) FROM ( SELECT * FROM k where a = true ); ```

POST/v1/{parent}:runAggregationQuery

Use it in a workflow

  1. Add a step and choose the Firestore connector.
  2. Pick the Firestore.projects.databases.documents.run Aggregation Query action (under projects).
  3. Fill in the fields below, then reference the result from later steps as {{firestoreProjectsDatabasesDocumentsRunAggregationQuery.response.data}}.

Request

Path parameters

parentstringrequired

Required. The parent resource name. In the format: `projects/{project_id}/databases/{database_id}/documents` or `projects/{project_id}/databases/{database_id}/documents/{document_path}`. For example: `projects/my-project/databases/my-database/documents` or `projects/my-project/databases/my-database/documents/chatrooms/my-chatroom`

Query parameters

$.xgafvstring

V1 error format.

One of12

access_tokenstring

OAuth access token.

altstring

Data format for response.

One ofjsonmediaproto

callbackstring

JSONP

fieldsstring

Selector specifying which fields to include in a partial response.

keystring

API key. Your API key identifies your project and provides you with API access, quota, and reports. Required unless you provide an OAuth 2.0 token.

oauth_tokenstring

OAuth 2.0 token for the current user.

prettyPrintboolean

Returns response with indentations and line breaks.

quotaUserstring

Available to use for quota purposes for server-side applications. Can be any arbitrary string assigned to a user, but should not exceed 40 characters.

upload_protocolstring

Upload protocol for media (e.g. "raw", "multipart").

uploadTypestring

Legacy upload protocol for media (e.g. "media", "multipart").

Request body

Enter the body as JSON in the step's Body field.

newTransactionobject

Options for creating a new transaction.

readOnlyobject1 fields

Options for a transaction that can only be used to read documents.

readWriteobject1 fields

Options for a transaction that can be used to read and write documents.

readTimestring (google-datetime)

Executes the query at the given timestamp. Requires: * Cannot be more than 270 seconds in the past.

structuredAggregationQueryobject

Firestore query for running an aggregation over a StructuredQuery.

aggregationsarray<object>2 fields

Optional. Series of aggregations to apply over the results of the `structured_query`. Requires: * A minimum of one and maximum of five aggregations per query.

structuredQueryobject8 fields

A Firestore query.

transactionstring (byte)

Run the aggregation within an already active transaction. The value here is the opaque transaction ID to execute the query in.

json
{
  "newTransaction": {
    "readOnly": {
      "readTime": "string"
    },
    "readWrite": {
      "retryTransaction": "string"
    }
  },
  "readTime": "string",
  "structuredAggregationQuery": {
    "aggregations": [
      {
        "alias": "string",
        "count": {
          "upTo": "string"
        }
      }
    ],
    "structuredQuery": {
      "endAt": {
        "before": false,
        "values": [
          {
            "arrayValue": {
              "values": null
            },
            "booleanValue": false,
            "bytesValue": "string",
            "doubleValue": 0,
            "geoPointValue": {
              "latitude": null,
              "longitude": null
            },
            "integerValue": "string",
            "mapValue": {
              "fields": null
            },
            "nullValue": "NULL_VALUE",
            "referenceValue": "string",
            "stringValue": "string",
            "timestampValue": "string"
          }
        ]
      },
      "from": [
        {
          "allDescendants": false,
          "collectionId": "string"
        }
      ],
      "limit": 0,
      "offset": 0,
      "orderBy": [
        {
          "direction": "DIRECTION_UNSPECIFIED",
          "field": {
            "fieldPath": "string"
          }
        }
      ],
      "select": {
        "fields": [
          {
            "fieldPath": "string"
          }
        ]
      },
      "startAt": {
        "before": false,
        "values": [
          {
            "arrayValue": {
              "values": null
            },
            "booleanValue": false,
            "bytesValue": "string",
            "doubleValue": 0,
            "geoPointValue": {
              "latitude": null,
              "longitude": null
            },
            "integerValue": "string",
            "mapValue": {
              "fields": null
            },
            "nullValue": "NULL_VALUE",
            "referenceValue": "string",
            "stringValue": "string",
            "timestampValue": "string"
          }
        ]
      },
      "where": {
        "compositeFilter": {
          "filters": [
            {}
          ],
          "op": "OPERATOR_UNSPECIFIED"
        },
        "fieldFilter": {
          "field": {
            "fieldPath": "string"
          },
          "op": "OPERATOR_UNSPECIFIED",
          "value": {
            "arrayValue": {
              "values": null
            },
            "booleanValue": false,
            "bytesValue": "string",
            "doubleValue": 0,
            "geoPointValue": {
              "latitude": null,
              "longitude": null
            },
            "integerValue": "string",
            "mapValue": {
              "fields": null
            },
            "nullValue": "NULL_VALUE",
            "referenceValue": "string",
            "stringValue": "string",
            "timestampValue": "string"
          }
        },
        "unaryFilter": {
          "field": {
            "fieldPath": "string"
          },
          "op": "OPERATOR_UNSPECIFIED"
        }
      }
    }
  },
  "transaction": "string"
}

Response

Returns 200 with an object. Read it in later steps with {{firestoreProjectsDatabasesDocumentsRunAggregationQuery.response.data.<field>}}.

readTimestring (google-datetime)

The time at which the aggregate result was computed. This is always monotonically increasing; in this case, the previous AggregationResult in the result stream are guaranteed not to have changed between their `read_time` and this one. If the query returns no results, a response with `read_time` and no `result` will be sent, and this represents the time at which the query was run.

resultobject

The result of a single bucket from a Firestore aggregation query. The keys of `aggregate_fields` are the same for all results in an aggregation query, unlike document queries which can have different fields present for each result.

aggregateFieldsobject

The result of the aggregation functions, ex: `COUNT(*) AS total_docs`. The key is the alias assigned to the aggregation function on input and the size of this map equals the number of aggregation functions in the query.

transactionstring (byte)

The transaction that was started as part of this request. Only present on the first response when the request requested to start a new transaction.

json
{
  "readTime": "string",
  "result": {
    "aggregateFields": {}
  },
  "transaction": "string"
}

Need more? See the Firestore guide for connection setup and behaviour shared by every action.

Firestore.projects.databases.documents.run Aggregation Query — Firestore — Documentation