Skip to main content

documents

Creates, updates, deletes, gets or lists a documents resource.

Overview​

Namedocuments
TypeResource
Idgoogle.firestore.documents

Fields​

The following fields are returned by SELECT queries:

NameDatatypeDescription
namestringThe resource name of the document, for example projects/{project_id}/databases/{database_id}/documents/{document_path}.
createTimestring (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.
fieldsobjectThe 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.
updateTimestring (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.

Methods​

The following methods are available for this resource:

NameAccessible byRequired ParamsOptional ParamsDescription
listselectprojectsId, databasesId, documentsId, documentsId1, collectionIdmask.fieldPaths, orderBy, pageSize, pageToken, readTime, recursive, requestOptions.requestTags, showMissing, transactionLists documents.
getselectprojectsId, databasesId, documentsId, documentsId1mask.fieldPaths, readTime, requestOptions.requestTags, transactionGets a single document.
list_documentsselectprojectsId, databasesId, collectionIdmask.fieldPaths, orderBy, pageSize, pageToken, readTime, recursive, requestOptions.requestTags, showMissing, transactionLists documents.
listenselectprojectsId, databasesIdListens to changes. This method is only available via gRPC or WebChannel (not REST).
create_documentinsertprojectsId, databasesId, documentsId, collectionIddocumentId, mask.fieldPaths, requestOptions.requestTagsCreates a new document.
patchupdateprojectsId, databasesId, documentsId, documentsId1currentDocument.exists, currentDocument.updateTime, mask.fieldPaths, requestOptions.requestTags, updateMask.fieldPathsUpdates or inserts a document.
deletedeleteprojectsId, databasesId, documentsId, documentsId1currentDocument.exists, currentDocument.updateTime, requestOptions.requestTagsDeletes a document.
batch_getexecprojectsId, databasesIdGets multiple documents. Documents returned by this method are not guaranteed to be returned in the same order that they were requested.
batch_writeexecprojectsId, databasesIdApplies 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.
begin_transactionexecprojectsId, databasesIdStarts a new transaction.
commitexecprojectsId, databasesIdCommits a transaction, while optionally updating documents.
execute_pipelineexecprojectsId, databasesIdExecutes a pipeline query.
partition_queryexecprojectsId, databasesId, documentsId, documentsId1Partitions 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.
rollbackexecprojectsId, databasesIdRolls back a transaction.
run_aggregation_queryexecprojectsId, databasesId, documentsId, documentsId1Runs 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 );
run_queryexecprojectsId, databasesId, documentsId, documentsId1Runs a query.
writeexecprojectsId, databasesIdStreams batches of document updates and deletes, in order. This method is only available via gRPC or WebChannel (not REST).

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.

NameDatatypeDescription
collectionIdstring
databasesIdstring
documentsIdstring
documentsId1string
projectsIdstring
currentDocument.existsboolean
currentDocument.updateTimestring (google-datetime)
documentIdstring
mask.fieldPathsstring
orderBystring
pageSizeinteger (int32)
pageTokenstring
readTimestring (google-datetime)
recursiveboolean
requestOptions.requestTagsstring
showMissingboolean
transactionstring (byte)
updateMask.fieldPathsstring

SELECT examples​

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 mask.fieldPaths = '{{ mask.fieldPaths }}'
AND orderBy = '{{ orderBy }}'
AND pageSize = '{{ pageSize }}'
AND pageToken = '{{ pageToken }}'
AND readTime = '{{ readTime }}'
AND recursive = '{{ recursive }}'
AND requestOptions.requestTags = '{{ requestOptions.requestTags }}'
AND showMissing = '{{ showMissing }}'
AND transaction = '{{ transaction }}'
;

INSERT examples​

Creates a new document.

INSERT INTO google.firestore.documents (
data__createTime,
data__fields,
data__name,
data__updateTime,
projectsId,
databasesId,
documentsId,
collectionId,
documentId,
mask.fieldPaths,
requestOptions.requestTags
)
SELECT
'{{ createTime }}',
'{{ fields }}',
'{{ name }}',
'{{ updateTime }}',
'{{ projectsId }}',
'{{ databasesId }}',
'{{ documentsId }}',
'{{ collectionId }}',
'{{ documentId }}',
'{{ mask.fieldPaths }}',
'{{ requestOptions.requestTags }}'
RETURNING
name,
createTime,
fields,
updateTime
;

UPDATE examples​

Updates or inserts a document.

UPDATE google.firestore.documents
SET
data__createTime = '{{ createTime }}',
data__fields = '{{ fields }}',
data__name = '{{ name }}',
data__updateTime = '{{ updateTime }}'
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}}'
AND mask.fieldPaths = '{{ mask.fieldPaths}}'
AND requestOptions.requestTags = '{{ requestOptions.requestTags}}'
AND updateMask.fieldPaths = '{{ updateMask.fieldPaths}}'
RETURNING
name,
createTime,
fields,
updateTime;

DELETE examples​

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 }}'
AND requestOptions.requestTags = '{{ requestOptions.requestTags }}'
;

Lifecycle Methods​

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=
'{
"documents": "{{ documents }}",
"mask": "{{ mask }}",
"newTransaction": "{{ newTransaction }}",
"readTime": "{{ readTime }}",
"requestOptions": "{{ requestOptions }}",
"transaction": "{{ transaction }}"
}'
;