Cloud Firestore V1 API - Class Google::Cloud::Firestore::V1::Firestore::Client (v0.7.1)

Reference documentation and code samples for the Cloud Firestore V1 API class Google::Cloud::Firestore::V1::Firestore::Client.

Client for the Firestore service.

The Cloud Firestore service.

Cloud Firestore is a fast, fully managed, serverless, cloud-native NoSQL document database that simplifies storing, syncing, and querying data for your mobile, web, and IoT apps at global scale. Its client libraries provide live synchronization and offline support, while its security features and integrations with Firebase and Google Cloud Platform (GCP) accelerate building truly serverless apps.

Inherits

  • Object

Methods

.configure

def self.configure() { |config| ... } -> Client::Configuration

Configure the Firestore Client class.

See Configuration for a description of the configuration fields.

Yields
  • (config) — Configure the Client client.
Yield Parameter
Example
# Modify the configuration for all Firestore clients
::Google::Cloud::Firestore::V1::Firestore::Client.configure do |config|
  config.timeout = 10.0
end

#batch_get_documents

def batch_get_documents(request, options = nil) -> ::Enumerable<::Google::Cloud::Firestore::V1::BatchGetDocumentsResponse>
def batch_get_documents(database: nil, documents: nil, mask: nil, transaction: nil, new_transaction: nil, read_time: nil) -> ::Enumerable<::Google::Cloud::Firestore::V1::BatchGetDocumentsResponse>

Gets multiple documents.

Documents returned by this method are not guaranteed to be returned in the same order that they were requested.

Overloads
def batch_get_documents(request, options = nil) -> ::Enumerable<::Google::Cloud::Firestore::V1::BatchGetDocumentsResponse>
Pass arguments to batch_get_documents via a request object, either of type BatchGetDocumentsRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Firestore::V1::BatchGetDocumentsRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def batch_get_documents(database: nil, documents: nil, mask: nil, transaction: nil, new_transaction: nil, read_time: nil) -> ::Enumerable<::Google::Cloud::Firestore::V1::BatchGetDocumentsResponse>
Pass arguments to batch_get_documents via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • database (::String) — Required. The database name. In the format: projects/{project_id}/databases/{database_id}.
  • documents (::Array<::String>) — The names of the documents to retrieve. In the format: projects/{project_id}/databases/{database_id}/documents/{document_path}. The request will fail if any of the document is not a child resource of the given database. Duplicate names will be elided.
  • mask (::Google::Cloud::Firestore::V1::DocumentMask, ::Hash) — The fields to return. If not set, returns all fields.

    If a document has a field that is not present in this mask, that field will not be returned in the response.

  • transaction (::String) — Reads documents in a transaction.
  • new_transaction (::Google::Cloud::Firestore::V1::TransactionOptions, ::Hash) — Starts a new transaction and reads the documents. Defaults to a read-only transaction. The new transaction ID will be returned as the first response in the stream.
  • read_time (::Google::Protobuf::Timestamp, ::Hash) — Reads documents as they were at the given time. This may not be older than 270 seconds.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/firestore/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Firestore::V1::Firestore::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Firestore::V1::BatchGetDocumentsRequest.new

# Call the batch_get_documents method.
result = client.batch_get_documents request

# The returned object is a streamed enumerable yielding elements of
# type ::Google::Cloud::Firestore::V1::BatchGetDocumentsResponse.
result.each do |response|
  p response
end

#batch_write

def batch_write(request, options = nil) -> ::Google::Cloud::Firestore::V1::BatchWriteResponse
def batch_write(database: nil, writes: nil, labels: nil) -> ::Google::Cloud::Firestore::V1::BatchWriteResponse

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.

Overloads
def batch_write(request, options = nil) -> ::Google::Cloud::Firestore::V1::BatchWriteResponse
Pass arguments to batch_write via a request object, either of type BatchWriteRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Firestore::V1::BatchWriteRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def batch_write(database: nil, writes: nil, labels: nil) -> ::Google::Cloud::Firestore::V1::BatchWriteResponse
Pass arguments to batch_write via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • database (::String) — Required. The database name. In the format: projects/{project_id}/databases/{database_id}.
  • writes (::Array<::Google::Cloud::Firestore::V1::Write, ::Hash>) — The writes to apply.

    Method does not apply writes atomically and does not guarantee ordering. Each write succeeds or fails independently. You cannot write to the same document more than once per request.

  • labels (::Hash{::String => ::String}) — Labels associated with this batch write.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/firestore/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Firestore::V1::Firestore::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Firestore::V1::BatchWriteRequest.new

# Call the batch_write method.
result = client.batch_write request

# The returned object is of type Google::Cloud::Firestore::V1::BatchWriteResponse.
p result

#begin_transaction

def begin_transaction(request, options = nil) -> ::Google::Cloud::Firestore::V1::BeginTransactionResponse
def begin_transaction(database: nil, options: nil) -> ::Google::Cloud::Firestore::V1::BeginTransactionResponse

Starts a new transaction.

Overloads
def begin_transaction(request, options = nil) -> ::Google::Cloud::Firestore::V1::BeginTransactionResponse
Pass arguments to begin_transaction via a request object, either of type BeginTransactionRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Firestore::V1::BeginTransactionRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def begin_transaction(database: nil, options: nil) -> ::Google::Cloud::Firestore::V1::BeginTransactionResponse
Pass arguments to begin_transaction via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • database (::String) — Required. The database name. In the format: projects/{project_id}/databases/{database_id}.
  • options (::Google::Cloud::Firestore::V1::TransactionOptions, ::Hash) — The options for the transaction. Defaults to a read-write transaction.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/firestore/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Firestore::V1::Firestore::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Firestore::V1::BeginTransactionRequest.new

# Call the begin_transaction method.
result = client.begin_transaction request

# The returned object is of type Google::Cloud::Firestore::V1::BeginTransactionResponse.
p result

#commit

def commit(request, options = nil) -> ::Google::Cloud::Firestore::V1::CommitResponse
def commit(database: nil, writes: nil, transaction: nil) -> ::Google::Cloud::Firestore::V1::CommitResponse

Commits a transaction, while optionally updating documents.

Overloads
def commit(request, options = nil) -> ::Google::Cloud::Firestore::V1::CommitResponse
Pass arguments to commit via a request object, either of type CommitRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Firestore::V1::CommitRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def commit(database: nil, writes: nil, transaction: nil) -> ::Google::Cloud::Firestore::V1::CommitResponse
Pass arguments to commit via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • database (::String) — Required. The database name. In the format: projects/{project_id}/databases/{database_id}.
  • writes (::Array<::Google::Cloud::Firestore::V1::Write, ::Hash>) — The writes to apply.

    Always executed atomically and in order.

  • transaction (::String) — If set, applies all writes in this transaction, and commits it.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/firestore/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Firestore::V1::Firestore::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Firestore::V1::CommitRequest.new

# Call the commit method.
result = client.commit request

# The returned object is of type Google::Cloud::Firestore::V1::CommitResponse.
p result

#configure

def configure() { |config| ... } -> Client::Configuration

Configure the Firestore Client instance.

The configuration is set to the derived mode, meaning that values can be changed, but structural changes (adding new fields, etc.) are not allowed. Structural changes should be made on Client.configure.

See Configuration for a description of the configuration fields.

Yields
  • (config) — Configure the Client client.
Yield Parameter

#create_document

def create_document(request, options = nil) -> ::Google::Cloud::Firestore::V1::Document
def create_document(parent: nil, collection_id: nil, document_id: nil, document: nil, mask: nil) -> ::Google::Cloud::Firestore::V1::Document

Creates a new document.

Overloads
def create_document(request, options = nil) -> ::Google::Cloud::Firestore::V1::Document
Pass arguments to create_document via a request object, either of type CreateDocumentRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Firestore::V1::CreateDocumentRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def create_document(parent: nil, collection_id: nil, document_id: nil, document: nil, mask: nil) -> ::Google::Cloud::Firestore::V1::Document
Pass arguments to create_document via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • parent (::String) — Required. The parent resource. For example: projects/{project_id}/databases/{database_id}/documents or projects/{project_id}/databases/{database_id}/documents/chatrooms/{chatroom_id}
  • collection_id (::String) — Required. The collection ID, relative to parent, to list. For example: chatrooms.
  • document_id (::String) — The client-assigned document ID to use for this document.

    Optional. If not specified, an ID will be assigned by the service.

  • document (::Google::Cloud::Firestore::V1::Document, ::Hash) — Required. The document to create. name must not be set.
  • mask (::Google::Cloud::Firestore::V1::DocumentMask, ::Hash) — The fields to return. If not set, returns all fields.

    If the document has a field that is not present in this mask, that field will not be returned in the response.

Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/firestore/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Firestore::V1::Firestore::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Firestore::V1::CreateDocumentRequest.new

# Call the create_document method.
result = client.create_document request

# The returned object is of type Google::Cloud::Firestore::V1::Document.
p result

#delete_document

def delete_document(request, options = nil) -> ::Google::Protobuf::Empty
def delete_document(name: nil, current_document: nil) -> ::Google::Protobuf::Empty

Deletes a document.

Overloads
def delete_document(request, options = nil) -> ::Google::Protobuf::Empty
Pass arguments to delete_document via a request object, either of type DeleteDocumentRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Firestore::V1::DeleteDocumentRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def delete_document(name: nil, current_document: nil) -> ::Google::Protobuf::Empty
Pass arguments to delete_document via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • name (::String) — Required. The resource name of the Document to delete. In the format: projects/{project_id}/databases/{database_id}/documents/{document_path}.
  • current_document (::Google::Cloud::Firestore::V1::Precondition, ::Hash) — An optional precondition on the document. The request will fail if this is set and not met by the target document.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/firestore/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Firestore::V1::Firestore::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Firestore::V1::DeleteDocumentRequest.new

# Call the delete_document method.
result = client.delete_document request

# The returned object is of type Google::Protobuf::Empty.
p result

#get_document

def get_document(request, options = nil) -> ::Google::Cloud::Firestore::V1::Document
def get_document(name: nil, mask: nil, transaction: nil, read_time: nil) -> ::Google::Cloud::Firestore::V1::Document

Gets a single document.

Overloads
def get_document(request, options = nil) -> ::Google::Cloud::Firestore::V1::Document
Pass arguments to get_document via a request object, either of type GetDocumentRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Firestore::V1::GetDocumentRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def get_document(name: nil, mask: nil, transaction: nil, read_time: nil) -> ::Google::Cloud::Firestore::V1::Document
Pass arguments to get_document via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • name (::String) — Required. The resource name of the Document to get. In the format: projects/{project_id}/databases/{database_id}/documents/{document_path}.
  • mask (::Google::Cloud::Firestore::V1::DocumentMask, ::Hash) — The fields to return. If not set, returns all fields.

    If the document has a field that is not present in this mask, that field will not be returned in the response.

  • transaction (::String) — Reads the document in a transaction.
  • read_time (::Google::Protobuf::Timestamp, ::Hash) — Reads the version of the document at the given time. This may not be older than 270 seconds.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/firestore/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Firestore::V1::Firestore::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Firestore::V1::GetDocumentRequest.new

# Call the get_document method.
result = client.get_document request

# The returned object is of type Google::Cloud::Firestore::V1::Document.
p result

#initialize

def initialize() { |config| ... } -> Client

Create a new Firestore client object.

Yields
  • (config) — Configure the Firestore client.
Yield Parameter
Returns
  • (Client) — a new instance of Client
Example
# Create a client using the default configuration
client = ::Google::Cloud::Firestore::V1::Firestore::Client.new

# Create a client using a custom configuration
client = ::Google::Cloud::Firestore::V1::Firestore::Client.new do |config|
  config.timeout = 10.0
end

#list_collection_ids

def list_collection_ids(request, options = nil) -> ::Google::Cloud::Firestore::V1::ListCollectionIdsResponse
def list_collection_ids(parent: nil, page_size: nil, page_token: nil, read_time: nil) -> ::Google::Cloud::Firestore::V1::ListCollectionIdsResponse

Lists all the collection IDs underneath a document.

Overloads
def list_collection_ids(request, options = nil) -> ::Google::Cloud::Firestore::V1::ListCollectionIdsResponse
Pass arguments to list_collection_ids via a request object, either of type ListCollectionIdsRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Firestore::V1::ListCollectionIdsRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def list_collection_ids(parent: nil, page_size: nil, page_token: nil, read_time: nil) -> ::Google::Cloud::Firestore::V1::ListCollectionIdsResponse
Pass arguments to list_collection_ids via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • parent (::String) — Required. The parent document. In the format: projects/{project_id}/databases/{database_id}/documents/{document_path}. For example: projects/my-project/databases/my-database/documents/chatrooms/my-chatroom
  • page_size (::Integer) — The maximum number of results to return.
  • page_token (::String) — A page token. Must be a value from ListCollectionIdsResponse.
  • read_time (::Google::Protobuf::Timestamp, ::Hash) — Reads documents as they were at the given time. This may not be older than 270 seconds.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/firestore/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Firestore::V1::Firestore::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Firestore::V1::ListCollectionIdsRequest.new

# Call the list_collection_ids method.
result = client.list_collection_ids request

# The returned object is of type Google::Cloud::Firestore::V1::ListCollectionIdsResponse.
p result

#list_documents

def list_documents(request, options = nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::Firestore::V1::Document>
def list_documents(parent: nil, collection_id: nil, page_size: nil, page_token: nil, order_by: nil, mask: nil, transaction: nil, read_time: nil, show_missing: nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::Firestore::V1::Document>

Lists documents.

Overloads
def list_documents(request, options = nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::Firestore::V1::Document>
Pass arguments to list_documents via a request object, either of type ListDocumentsRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Firestore::V1::ListDocumentsRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def list_documents(parent: nil, collection_id: nil, page_size: nil, page_token: nil, order_by: nil, mask: nil, transaction: nil, read_time: nil, show_missing: nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::Firestore::V1::Document>
Pass arguments to list_documents via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • parent (::String) — 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
  • collection_id (::String) — Required. The collection ID, relative to parent, to list. For example: chatrooms or messages.
  • page_size (::Integer) — The maximum number of documents to return.
  • page_token (::String) — The next_page_token value returned from a previous List request, if any.
  • order_by (::String) — The order to sort results by. For example: priority desc, name.
  • mask (::Google::Cloud::Firestore::V1::DocumentMask, ::Hash) — The fields to return. If not set, returns all fields.

    If a document has a field that is not present in this mask, that field will not be returned in the response.

  • transaction (::String) — Reads documents in a transaction.
  • read_time (::Google::Protobuf::Timestamp, ::Hash) — Reads documents as they were at the given time. This may not be older than 270 seconds.
  • show_missing (::Boolean) — If the list should show missing documents. A missing document is a document that does not exist but has sub-documents. These documents will be returned with a key but will not have fields, Document.create_time, or Document.update_time set.

    Requests with show_missing may not specify where or order_by.

Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Returns
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/firestore/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Firestore::V1::Firestore::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Firestore::V1::ListDocumentsRequest.new

# Call the list_documents method.
result = client.list_documents request

# The returned object is of type Gapic::PagedEnumerable. You can
# iterate over all elements by calling #each, and the enumerable
# will lazily make API calls to fetch subsequent pages. Other
# methods are also available for managing paging directly.
result.each do |response|
  # Each element is of type ::Google::Cloud::Firestore::V1::Document.
  p response
end

#listen

def listen(request, options = nil) { |response, operation| ... } -> ::Enumerable<::Google::Cloud::Firestore::V1::ListenResponse>

Listens to changes.

Parameters
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/firestore/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Firestore::V1::Firestore::Client.new

# Create an input stream
input = Gapic::StreamInput.new

# Call the listen method to start streaming.
output = client.listen input

# Send requests on the stream. For each request, pass in keyword
# arguments to set fields. Be sure to close the stream when done.
input << Google::Cloud::Firestore::V1::ListenRequest.new
input << Google::Cloud::Firestore::V1::ListenRequest.new
input.close

# Handle streamed responses. These may be interleaved with inputs.
# Each response is of type ::Google::Cloud::Firestore::V1::ListenResponse.
output.each do |response|
  p response
end

#partition_query

def partition_query(request, options = nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::Firestore::V1::Cursor>
def partition_query(parent: nil, structured_query: nil, partition_count: nil, page_token: nil, page_size: nil, read_time: nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::Firestore::V1::Cursor>

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.

Overloads
def partition_query(request, options = nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::Firestore::V1::Cursor>
Pass arguments to partition_query via a request object, either of type PartitionQueryRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Firestore::V1::PartitionQueryRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def partition_query(parent: nil, structured_query: nil, partition_count: nil, page_token: nil, page_size: nil, read_time: nil) -> ::Gapic::PagedEnumerable<::Google::Cloud::Firestore::V1::Cursor>
Pass arguments to partition_query via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • parent (::String) — Required. The parent resource name. In the format: projects/{project_id}/databases/{database_id}/documents. Document resource names are not supported; only database resource names can be specified.
  • structured_query (::Google::Cloud::Firestore::V1::StructuredQuery, ::Hash) — A structured query. Query must specify collection with all descendants and be ordered by name ascending. Other filters, order bys, limits, offsets, and start/end cursors are not supported.
  • partition_count (::Integer) — The desired maximum number of partition points. The partitions may be returned across multiple pages of results. The number must be positive. The actual number of partitions returned may be fewer.

    For example, this may be set to one fewer than the number of parallel queries to be run, or in running a data pipeline job, one fewer than the number of workers or compute instances available.

  • page_token (::String) — The next_page_token value returned from a previous call to PartitionQuery that may be used to get an additional set of results. There are no ordering guarantees between sets of results. Thus, using multiple sets of results will require merging the different result sets.

    For example, two subsequent calls using a page_token may return:

    • cursor B, cursor M, cursor Q
    • cursor A, cursor U, cursor W

    To obtain a complete result set ordered with respect to the results of the query supplied to PartitionQuery, the results sets should be merged: cursor A, cursor B, cursor M, cursor Q, cursor U, cursor W

  • page_size (::Integer) — The maximum number of partitions to return in this call, subject to partition_count.

    For example, if partition_count = 10 and page_size = 8, the first call to PartitionQuery will return up to 8 partitions and a next_page_token if more results exist. A second call to PartitionQuery will return up to 2 partitions, to complete the total of 10 specified in partition_count.

  • read_time (::Google::Protobuf::Timestamp, ::Hash) — Reads documents as they were at the given time. This may not be older than 270 seconds.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Returns
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/firestore/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Firestore::V1::Firestore::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Firestore::V1::PartitionQueryRequest.new

# Call the partition_query method.
result = client.partition_query request

# The returned object is of type Gapic::PagedEnumerable. You can
# iterate over all elements by calling #each, and the enumerable
# will lazily make API calls to fetch subsequent pages. Other
# methods are also available for managing paging directly.
result.each do |response|
  # Each element is of type ::Google::Cloud::Firestore::V1::Cursor.
  p response
end

#rollback

def rollback(request, options = nil) -> ::Google::Protobuf::Empty
def rollback(database: nil, transaction: nil) -> ::Google::Protobuf::Empty

Rolls back a transaction.

Overloads
def rollback(request, options = nil) -> ::Google::Protobuf::Empty
Pass arguments to rollback via a request object, either of type RollbackRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Firestore::V1::RollbackRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def rollback(database: nil, transaction: nil) -> ::Google::Protobuf::Empty
Pass arguments to rollback via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • database (::String) — Required. The database name. In the format: projects/{project_id}/databases/{database_id}.
  • transaction (::String) — Required. The transaction to roll back.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/firestore/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Firestore::V1::Firestore::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Firestore::V1::RollbackRequest.new

# Call the rollback method.
result = client.rollback request

# The returned object is of type Google::Protobuf::Empty.
p result

#run_query

def run_query(request, options = nil) -> ::Enumerable<::Google::Cloud::Firestore::V1::RunQueryResponse>
def run_query(parent: nil, structured_query: nil, transaction: nil, new_transaction: nil, read_time: nil) -> ::Enumerable<::Google::Cloud::Firestore::V1::RunQueryResponse>

Runs a query.

Overloads
def run_query(request, options = nil) -> ::Enumerable<::Google::Cloud::Firestore::V1::RunQueryResponse>
Pass arguments to run_query via a request object, either of type RunQueryRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Firestore::V1::RunQueryRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def run_query(parent: nil, structured_query: nil, transaction: nil, new_transaction: nil, read_time: nil) -> ::Enumerable<::Google::Cloud::Firestore::V1::RunQueryResponse>
Pass arguments to run_query via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • parent (::String) — 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
  • structured_query (::Google::Cloud::Firestore::V1::StructuredQuery, ::Hash) — A structured query.
  • transaction (::String) — Run the query within an already active transaction.

    The value here is the opaque transaction ID to execute the query in.

  • new_transaction (::Google::Cloud::Firestore::V1::TransactionOptions, ::Hash) — Starts a new transaction and reads the documents. Defaults to a read-only transaction. The new transaction ID will be returned as the first response in the stream.
  • read_time (::Google::Protobuf::Timestamp, ::Hash) — Reads documents as they were at the given time. This may not be older than 270 seconds.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/firestore/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Firestore::V1::Firestore::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Firestore::V1::RunQueryRequest.new

# Call the run_query method.
result = client.run_query request

# The returned object is a streamed enumerable yielding elements of
# type ::Google::Cloud::Firestore::V1::RunQueryResponse.
result.each do |response|
  p response
end

#update_document

def update_document(request, options = nil) -> ::Google::Cloud::Firestore::V1::Document
def update_document(document: nil, update_mask: nil, mask: nil, current_document: nil) -> ::Google::Cloud::Firestore::V1::Document

Updates or inserts a document.

Overloads
def update_document(request, options = nil) -> ::Google::Cloud::Firestore::V1::Document
Pass arguments to update_document via a request object, either of type UpdateDocumentRequest or an equivalent Hash.
Parameters
  • request (::Google::Cloud::Firestore::V1::UpdateDocumentRequest, ::Hash) — A request object representing the call parameters. Required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash.
  • options (::Gapic::CallOptions, ::Hash) — Overrides the default settings for this call, e.g, timeout, retries, etc. Optional.
def update_document(document: nil, update_mask: nil, mask: nil, current_document: nil) -> ::Google::Cloud::Firestore::V1::Document
Pass arguments to update_document via keyword arguments. Note that at least one keyword argument is required. To specify no parameters, or to keep all the default parameter values, pass an empty Hash as a request object (see above).
Parameters
  • document (::Google::Cloud::Firestore::V1::Document, ::Hash) — Required. The updated document. Creates the document if it does not already exist.
  • update_mask (::Google::Cloud::Firestore::V1::DocumentMask, ::Hash) — The fields to update. None of the field paths in the mask may contain a reserved name.

    If the document exists on the server and has fields not referenced in the mask, they are left unchanged. Fields referenced in the mask, but not present in the input document, are deleted from the document on the server.

  • mask (::Google::Cloud::Firestore::V1::DocumentMask, ::Hash) — The fields to return. If not set, returns all fields.

    If the document has a field that is not present in this mask, that field will not be returned in the response.

  • current_document (::Google::Cloud::Firestore::V1::Precondition, ::Hash) — An optional precondition on the document. The request will fail if this is set and not met by the target document.
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/firestore/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Firestore::V1::Firestore::Client.new

# Create a request. To set request fields, pass in keyword arguments.
request = Google::Cloud::Firestore::V1::UpdateDocumentRequest.new

# Call the update_document method.
result = client.update_document request

# The returned object is of type Google::Cloud::Firestore::V1::Document.
p result

#write

def write(request, options = nil) { |response, operation| ... } -> ::Enumerable<::Google::Cloud::Firestore::V1::WriteResponse>

Streams batches of document updates and deletes, in order.

Parameters
Yields
  • (response, operation) — Access the result along with the RPC operation
Yield Parameters
Raises
  • (::Google::Cloud::Error) — if the RPC is aborted.
Example

Basic example

require "google/cloud/firestore/v1"

# Create a client object. The client can be reused for multiple calls.
client = Google::Cloud::Firestore::V1::Firestore::Client.new

# Create an input stream
input = Gapic::StreamInput.new

# Call the write method to start streaming.
output = client.write input

# Send requests on the stream. For each request, pass in keyword
# arguments to set fields. Be sure to close the stream when done.
input << Google::Cloud::Firestore::V1::WriteRequest.new
input << Google::Cloud::Firestore::V1::WriteRequest.new
input.close

# Handle streamed responses. These may be interleaved with inputs.
# Each response is of type ::Google::Cloud::Firestore::V1::WriteResponse.
output.each do |response|
  p response
end