documents
Creates, updates, deletes, gets or lists a documents resource.
Overview
| Name | documents |
| Type | Resource |
| Id | google.firestore.documents |
Fields
The following fields are returned by SELECT queries:
- list
- get
- list_documents
- listen
| Name | Datatype | Description |
|---|---|---|
name | string | The resource name of the document, for example projects/{project_id}/databases/{database_id}/documents/{document_path}. |
createTime | string (google-datetime) | Output only. The time at which the document was created. This value increases monotonically when a document is deleted then recreated. It can also be compared to values from other documents and the read_time of a query. |
fields | object | The document's fields. The map keys represent field names. Field names matching the regular expression __.*__ are reserved. Reserved field names are forbidden except in certain documented contexts. The field names, represented as UTF-8, must not exceed 1,500 bytes and cannot be empty. Field paths may be used in other contexts to refer to structured fields defined here. For map_value, the field path is represented by a dot-delimited (.) string of segments. Each segment is either a simple field name (defined below) or a quoted field name. For example, the structured field "foo" : { map_value: { "x&y" : { string_value: "hello" }}} would be represented by the field path foo.`x&y`. A simple field name contains only characters a to z, A to Z, 0 to 9, or _, and must not start with 0 to 9. For example, foo_bar_17. A quoted field name starts and ends with ` and may contain any character. Some characters, including `, must be escaped using a \. For example, `x&y` represents x&y and `bak\`tik` represents bak`tik. |
updateTime | string (google-datetime) | Output only. The time at which the document was last changed. This value is initially set to the create_time then increases monotonically with each change to the document. It can also be compared to values from other documents and the read_time of a query. |
| Name | Datatype | Description |
|---|---|---|
name | string | The resource name of the document, for example projects/{project_id}/databases/{database_id}/documents/{document_path}. |
createTime | string (google-datetime) | Output only. The time at which the document was created. This value increases monotonically when a document is deleted then recreated. It can also be compared to values from other documents and the read_time of a query. |
fields | object | The document's fields. The map keys represent field names. Field names matching the regular expression __.*__ are reserved. Reserved field names are forbidden except in certain documented contexts. The field names, represented as UTF-8, must not exceed 1,500 bytes and cannot be empty. Field paths may be used in other contexts to refer to structured fields defined here. For map_value, the field path is represented by a dot-delimited (.) string of segments. Each segment is either a simple field name (defined below) or a quoted field name. For example, the structured field "foo" : { map_value: { "x&y" : { string_value: "hello" }}} would be represented by the field path foo.`x&y`. A simple field name contains only characters a to z, A to Z, 0 to 9, or _, and must not start with 0 to 9. For example, foo_bar_17. A quoted field name starts and ends with ` and may contain any character. Some characters, including `, must be escaped using a \. For example, `x&y` represents x&y and `bak\`tik` represents bak`tik. |
updateTime | string (google-datetime) | Output only. The time at which the document was last changed. This value is initially set to the create_time then increases monotonically with each change to the document. It can also be compared to values from other documents and the read_time of a query. |
| Name | Datatype | Description |
|---|---|---|
name | string | The resource name of the document, for example projects/{project_id}/databases/{database_id}/documents/{document_path}. |
createTime | string (google-datetime) | Output only. The time at which the document was created. This value increases monotonically when a document is deleted then recreated. It can also be compared to values from other documents and the read_time of a query. |
fields | object | The document's fields. The map keys represent field names. Field names matching the regular expression __.*__ are reserved. Reserved field names are forbidden except in certain documented contexts. The field names, represented as UTF-8, must not exceed 1,500 bytes and cannot be empty. Field paths may be used in other contexts to refer to structured fields defined here. For map_value, the field path is represented by a dot-delimited (.) string of segments. Each segment is either a simple field name (defined below) or a quoted field name. For example, the structured field "foo" : { map_value: { "x&y" : { string_value: "hello" }}} would be represented by the field path foo.`x&y`. A simple field name contains only characters a to z, A to Z, 0 to 9, or _, and must not start with 0 to 9. For example, foo_bar_17. A quoted field name starts and ends with ` and may contain any character. Some characters, including `, must be escaped using a \. For example, `x&y` represents x&y and `bak\`tik` represents bak`tik. |
updateTime | string (google-datetime) | Output only. The time at which the document was last changed. This value is initially set to the create_time then increases monotonically with each change to the document. It can also be compared to values from other documents and the read_time of a query. |
| Name | Datatype | Description |
|---|---|---|
documentChange | object | A Document has changed. (id: DocumentChange) |
documentDelete | object | A Document has been deleted. (id: DocumentDelete) |
documentRemove | object | A Document has been removed from a target (because it is no longer relevant to that target). (id: DocumentRemove) |
filter | object | A filter to apply to the set of documents previously returned for the given target. Returned when documents may have been removed from the given target, but the exact documents are unknown. (id: ExistenceFilter) |
targetChange | object | Targets have changed. (id: TargetChange) |
Methods
The following methods are available for this resource:
| Name | Accessible by | Required Params | Optional Params | Description |
|---|---|---|---|---|
list | select | projectsId, databasesId, documentsId, documentsId1, collectionId | transaction, pageSize, showMissing, mask.fieldPaths, pageToken, orderBy, readTime | Lists documents. |
get | select | projectsId, databasesId, documentsId, documentsId1 | mask.fieldPaths, readTime, transaction | Gets a single document. |
list_documents | select | projectsId, databasesId, collectionId | pageSize, pageToken, showMissing, mask.fieldPaths, readTime, orderBy, transaction | Lists documents. |
listen | select | projectsId, databasesId | Listens to changes. This method is only available via gRPC or WebChannel (not REST). | |
create_document | insert | projectsId, databasesId, documentsId, collectionId | documentId, mask.fieldPaths | Creates a new document. |
patch | update | projectsId, databasesId, documentsId, documentsId1 | currentDocument.exists, updateMask.fieldPaths, currentDocument.updateTime, mask.fieldPaths | Updates or inserts a document. |
delete | delete | projectsId, databasesId, documentsId, documentsId1 | currentDocument.exists, currentDocument.updateTime | Deletes a document. |
begin_transaction | exec | projectsId, databasesId | Starts a new transaction. | |
run_aggregation_query | exec | projectsId, databasesId, documentsId, documentsId1 | 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 ); | |
commit | exec | projectsId, databasesId | Commits a transaction, while optionally updating documents. | |
run_query | exec | projectsId, databasesId, documentsId, documentsId1 | Runs a query. | |
batch_get | exec | projectsId, databasesId | Gets multiple documents. Documents returned by this method are not guaranteed to be returned in the same order that they were requested. | |
write | exec | projectsId, databasesId | Streams batches of document updates and deletes, in order. This method is only available via gRPC or WebChannel (not REST). | |
batch_write | exec | projectsId, databasesId | Applies a batch of write operations. The BatchWrite method does not apply the write operations atomically and can apply them out of order. Method does not allow more than one write per document. Each write succeeds or fails independently. See the BatchWriteResponse for the success status of each write. If you require an atomically applied set of writes, use Commit instead. | |
partition_query | exec | projectsId, databasesId, documentsId, documentsId1 | Partitions a query by returning partition cursors that can be used to run the query in parallel. The returned partition cursors are split points that can be used by RunQuery as starting/end points for the query results. | |
rollback | exec | projectsId, databasesId | Rolls back a transaction. |
Parameters
Parameters can be passed in the WHERE clause of a query. Check the Methods section to see which parameters are required or optional for each operation.
| Name | Datatype | Description |
|---|---|---|
collectionId | string | |
databasesId | string | |
documentsId | string | |
documentsId1 | string | |
projectsId | string | |
currentDocument.exists | boolean | |
currentDocument.updateTime | string (google-datetime) | |
documentId | string | |
mask.fieldPaths | string | |
orderBy | string | |
pageSize | integer (int32) | |
pageToken | string | |
readTime | string (google-datetime) | |
showMissing | boolean | |
transaction | string (byte) | |
updateMask.fieldPaths | string |
SELECT examples
- list
- get
- list_documents
- listen
Lists documents.
SELECT
name,
createTime,
fields,
updateTime
FROM google.firestore.documents
WHERE projectsId = '{{ projectsId }}' -- required
AND databasesId = '{{ databasesId }}' -- required
AND documentsId = '{{ documentsId }}' -- required
AND documentsId1 = '{{ documentsId1 }}' -- required
AND collectionId = '{{ collectionId }}' -- required
AND transaction = '{{ transaction }}'
AND pageSize = '{{ pageSize }}'
AND showMissing = '{{ showMissing }}'
AND mask.fieldPaths = '{{ mask.fieldPaths }}'
AND pageToken = '{{ pageToken }}'
AND orderBy = '{{ orderBy }}'
AND readTime = '{{ readTime }}'
;
Gets a single document.
SELECT
name,
createTime,
fields,
updateTime
FROM google.firestore.documents
WHERE projectsId = '{{ projectsId }}' -- required
AND databasesId = '{{ databasesId }}' -- required
AND documentsId = '{{ documentsId }}' -- required
AND documentsId1 = '{{ documentsId1 }}' -- required
AND mask.fieldPaths = '{{ mask.fieldPaths }}'
AND readTime = '{{ readTime }}'
AND transaction = '{{ transaction }}'
;
Lists documents.
SELECT
name,
createTime,
fields,
updateTime
FROM google.firestore.documents
WHERE projectsId = '{{ projectsId }}' -- required
AND databasesId = '{{ databasesId }}' -- required
AND collectionId = '{{ collectionId }}' -- required
AND pageSize = '{{ pageSize }}'
AND pageToken = '{{ pageToken }}'
AND showMissing = '{{ showMissing }}'
AND mask.fieldPaths = '{{ mask.fieldPaths }}'
AND readTime = '{{ readTime }}'
AND orderBy = '{{ orderBy }}'
AND transaction = '{{ transaction }}'
;
Listens to changes. This method is only available via gRPC or WebChannel (not REST).
SELECT
documentChange,
documentDelete,
documentRemove,
filter,
targetChange
FROM google.firestore.documents
WHERE projectsId = '{{ projectsId }}' -- required
AND databasesId = '{{ databasesId }}' -- required
;
INSERT examples
- create_document
- Manifest
Creates a new document.
INSERT INTO google.firestore.documents (
data__updateTime,
data__name,
data__createTime,
data__fields,
projectsId,
databasesId,
documentsId,
collectionId,
documentId,
mask.fieldPaths
)
SELECT
'{{ updateTime }}',
'{{ name }}',
'{{ createTime }}',
'{{ fields }}',
'{{ projectsId }}',
'{{ databasesId }}',
'{{ documentsId }}',
'{{ collectionId }}',
'{{ documentId }}',
'{{ mask.fieldPaths }}'
RETURNING
name,
createTime,
fields,
updateTime
;
# Description fields are for documentation purposes
- name: documents
props:
- name: projectsId
value: string
description: Required parameter for the documents resource.
- name: databasesId
value: string
description: Required parameter for the documents resource.
- name: documentsId
value: string
description: Required parameter for the documents resource.
- name: collectionId
value: string
description: Required parameter for the documents resource.
- name: updateTime
value: string
description: >
Output only. The time at which the document was last changed. This value is initially set to the `create_time` then increases monotonically with each change to the document. It can also be compared to values from other documents and the `read_time` of a query.
- name: name
value: string
description: >
The resource name of the document, for example `projects/{project_id}/databases/{database_id}/documents/{document_path}`.
- name: createTime
value: string
description: >
Output only. The time at which the document was created. This value increases monotonically when a document is deleted then recreated. It can also be compared to values from other documents and the `read_time` of a query.
- name: fields
value: object
description: >
The document's fields. The map keys represent field names. Field names matching the regular expression `__.*__` are reserved. Reserved field names are forbidden except in certain documented contexts. The field names, represented as UTF-8, must not exceed 1,500 bytes and cannot be empty. Field paths may be used in other contexts to refer to structured fields defined here. For `map_value`, the field path is represented by a dot-delimited (`.`) string of segments. Each segment is either a simple field name (defined below) or a quoted field name. For example, the structured field `"foo" : { map_value: { "x&y" : { string_value: "hello" }}}` would be represented by the field path `` foo.`x&y` ``. A simple field name contains only characters `a` to `z`, `A` to `Z`, `0` to `9`, or `_`, and must not start with `0` to `9`. For example, `foo_bar_17`. A quoted field name starts and ends with `` ` `` and may contain any character. Some characters, including `` ` ``, must be escaped using a `\`. For example, `` `x&y` `` represents `x&y` and `` `bak\`tik` `` represents `` bak`tik ``.
- name: documentId
value: string
- name: mask.fieldPaths
value: string
UPDATE examples
- patch
Updates or inserts a document.
UPDATE google.firestore.documents
SET
data__updateTime = '{{ updateTime }}',
data__name = '{{ name }}',
data__createTime = '{{ createTime }}',
data__fields = '{{ fields }}'
WHERE
projectsId = '{{ projectsId }}' --required
AND databasesId = '{{ databasesId }}' --required
AND documentsId = '{{ documentsId }}' --required
AND documentsId1 = '{{ documentsId1 }}' --required
AND currentDocument.exists = {{ currentDocument.exists}}
AND updateMask.fieldPaths = '{{ updateMask.fieldPaths}}'
AND currentDocument.updateTime = '{{ currentDocument.updateTime}}'
AND mask.fieldPaths = '{{ mask.fieldPaths}}'
RETURNING
name,
createTime,
fields,
updateTime;
DELETE examples
- delete
Deletes a document.
DELETE FROM google.firestore.documents
WHERE projectsId = '{{ projectsId }}' --required
AND databasesId = '{{ databasesId }}' --required
AND documentsId = '{{ documentsId }}' --required
AND documentsId1 = '{{ documentsId1 }}' --required
AND currentDocument.exists = '{{ currentDocument.exists }}'
AND currentDocument.updateTime = '{{ currentDocument.updateTime }}'
;
Lifecycle Methods
- begin_transaction
- run_aggregation_query
- commit
- run_query
- batch_get
- write
- batch_write
- partition_query
- rollback
Starts a new transaction.
EXEC google.firestore.documents.begin_transaction
@projectsId='{{ projectsId }}' --required,
@databasesId='{{ databasesId }}' --required
@@json=
'{
"options": "{{ options }}"
}'
;
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 );
EXEC google.firestore.documents.run_aggregation_query
@projectsId='{{ projectsId }}' --required,
@databasesId='{{ databasesId }}' --required,
@documentsId='{{ documentsId }}' --required,
@documentsId1='{{ documentsId1 }}' --required
@@json=
'{
"transaction": "{{ transaction }}",
"readTime": "{{ readTime }}",
"explainOptions": "{{ explainOptions }}",
"structuredAggregationQuery": "{{ structuredAggregationQuery }}",
"newTransaction": "{{ newTransaction }}"
}'
;
Commits a transaction, while optionally updating documents.
EXEC google.firestore.documents.commit
@projectsId='{{ projectsId }}' --required,
@databasesId='{{ databasesId }}' --required
@@json=
'{
"transaction": "{{ transaction }}",
"writes": "{{ writes }}"
}'
;
Runs a query.
EXEC google.firestore.documents.run_query
@projectsId='{{ projectsId }}' --required,
@databasesId='{{ databasesId }}' --required,
@documentsId='{{ documentsId }}' --required,
@documentsId1='{{ documentsId1 }}' --required
@@json=
'{
"explainOptions": "{{ explainOptions }}",
"structuredQuery": "{{ structuredQuery }}",
"readTime": "{{ readTime }}",
"transaction": "{{ transaction }}",
"newTransaction": "{{ newTransaction }}"
}'
;
Gets multiple documents. Documents returned by this method are not guaranteed to be returned in the same order that they were requested.
EXEC google.firestore.documents.batch_get
@projectsId='{{ projectsId }}' --required,
@databasesId='{{ databasesId }}' --required
@@json=
'{
"readTime": "{{ readTime }}",
"newTransaction": "{{ newTransaction }}",
"mask": "{{ mask }}",
"documents": "{{ documents }}",
"transaction": "{{ transaction }}"
}'
;
Streams batches of document updates and deletes, in order. This method is only available via gRPC or WebChannel (not REST).
EXEC google.firestore.documents.write
@projectsId='{{ projectsId }}' --required,
@databasesId='{{ databasesId }}' --required
@@json=
'{
"labels": "{{ labels }}",
"streamId": "{{ streamId }}",
"writes": "{{ writes }}",
"streamToken": "{{ streamToken }}"
}'
;
Applies a batch of write operations. The BatchWrite method does not apply the write operations atomically and can apply them out of order. Method does not allow more than one write per document. Each write succeeds or fails independently. See the BatchWriteResponse for the success status of each write. If you require an atomically applied set of writes, use Commit instead.
EXEC google.firestore.documents.batch_write
@projectsId='{{ projectsId }}' --required,
@databasesId='{{ databasesId }}' --required
@@json=
'{
"labels": "{{ labels }}",
"writes": "{{ writes }}"
}'
;
Partitions a query by returning partition cursors that can be used to run the query in parallel. The returned partition cursors are split points that can be used by RunQuery as starting/end points for the query results.
EXEC google.firestore.documents.partition_query
@projectsId='{{ projectsId }}' --required,
@databasesId='{{ databasesId }}' --required,
@documentsId='{{ documentsId }}' --required,
@documentsId1='{{ documentsId1 }}' --required
@@json=
'{
"readTime": "{{ readTime }}",
"pageSize": {{ pageSize }},
"pageToken": "{{ pageToken }}",
"structuredQuery": "{{ structuredQuery }}",
"partitionCount": "{{ partitionCount }}"
}'
;
Rolls back a transaction.
EXEC google.firestore.documents.rollback
@projectsId='{{ projectsId }}' --required,
@databasesId='{{ databasesId }}' --required
@@json=
'{
"transaction": "{{ transaction }}"
}'
;