Firestore v1 API - Class FirestoreClient (3.6.0)

public abstract class FirestoreClient

Reference documentation and code samples for the Firestore v1 API class FirestoreClient.

Firestore client wrapper, for convenient use.

Inheritance

object > FirestoreClient

Derived Types

Namespace

Google.Cloud.Firestore.V1

Assembly

Google.Cloud.Firestore.V1.dll

Remarks

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 accelerate building truly serverless apps.

Properties

DefaultEndpoint

public static string DefaultEndpoint { get; }

The default endpoint for the Firestore service, which is a host of "firestore.googleapis.com" and a port of 443.

Property Value
TypeDescription
string

DefaultScopes

public static IReadOnlyList<string> DefaultScopes { get; }

The default Firestore scopes.

Property Value
TypeDescription
IReadOnlyListstring
Remarks

GrpcClient

public virtual Firestore.FirestoreClient GrpcClient { get; }

The underlying gRPC Firestore client

Property Value
TypeDescription
FirestoreFirestoreClient

LocationsClient

public virtual LocationsClient LocationsClient { get; }

The LocationsClient associated with this client.

Property Value
TypeDescription
LocationsClient

ServiceMetadata

public static ServiceMetadata ServiceMetadata { get; }

The service metadata associated with this client type.

Property Value
TypeDescription
ServiceMetadata

Settings

public virtual FirestoreSettings Settings { get; protected set; }

Returns the effective CallSettings used for each API call. This can be used to create a modified instance of CallSettings to pass for a single API request.

Property Value
TypeDescription
FirestoreSettings

Methods

BatchGetDocuments(BatchGetDocumentsRequest, CallSettings)

public virtual FirestoreClient.BatchGetDocumentsStream BatchGetDocuments(BatchGetDocumentsRequest request, CallSettings callSettings = null)

Gets multiple documents.

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

Parameters
NameDescription
requestBatchGetDocumentsRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
FirestoreClientBatchGetDocumentsStream

The server stream.

Example
// Create client
FirestoreClient firestoreClient = FirestoreClient.Create();
// Initialize request argument(s)
BatchGetDocumentsRequest request = new BatchGetDocumentsRequest
{
    Database = "",
    Documents = { "", },
    Mask = new DocumentMask(),
    Transaction = ByteString.Empty,
};
// Make the request, returning a streaming response
using FirestoreClient.BatchGetDocumentsStream response = firestoreClient.BatchGetDocuments(request);

// Read streaming responses from server until complete
// Note that C# 8 code can use await foreach
AsyncResponseStream<BatchGetDocumentsResponse> responseStream = response.GetResponseStream();
while (await responseStream.MoveNextAsync())
{
    BatchGetDocumentsResponse responseItem = responseStream.Current;
    // Do something with streamed response
}
// The response stream has completed

BatchWrite(BatchWriteRequest, CallSettings)

public virtual BatchWriteResponse BatchWrite(BatchWriteRequest request, CallSettings callSettings = null)

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][google.firestore.v1.BatchWriteResponse] for the success status of each write.

If you require an atomically applied set of writes, use [Commit][google.firestore.v1.Firestore.Commit] instead.

Parameters
NameDescription
requestBatchWriteRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
BatchWriteResponse

The RPC response.

Example
// Create client
FirestoreClient firestoreClient = FirestoreClient.Create();
// Initialize request argument(s)
BatchWriteRequest request = new BatchWriteRequest
{
    Database = "",
    Writes = { new Write(), },
    Labels = { { "", "" }, },
};
// Make the request
BatchWriteResponse response = firestoreClient.BatchWrite(request);

BatchWriteAsync(BatchWriteRequest, CallSettings)

public virtual Task<BatchWriteResponse> BatchWriteAsync(BatchWriteRequest request, CallSettings callSettings = null)

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][google.firestore.v1.BatchWriteResponse] for the success status of each write.

If you require an atomically applied set of writes, use [Commit][google.firestore.v1.Firestore.Commit] instead.

Parameters
NameDescription
requestBatchWriteRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
TaskBatchWriteResponse

A Task containing the RPC response.

Example
// Create client
FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();
// Initialize request argument(s)
BatchWriteRequest request = new BatchWriteRequest
{
    Database = "",
    Writes = { new Write(), },
    Labels = { { "", "" }, },
};
// Make the request
BatchWriteResponse response = await firestoreClient.BatchWriteAsync(request);

BatchWriteAsync(BatchWriteRequest, CancellationToken)

public virtual Task<BatchWriteResponse> BatchWriteAsync(BatchWriteRequest request, CancellationToken cancellationToken)

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][google.firestore.v1.BatchWriteResponse] for the success status of each write.

If you require an atomically applied set of writes, use [Commit][google.firestore.v1.Firestore.Commit] instead.

Parameters
NameDescription
requestBatchWriteRequest

The request object containing all of the parameters for the API call.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
TaskBatchWriteResponse

A Task containing the RPC response.

Example
// Create client
FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();
// Initialize request argument(s)
BatchWriteRequest request = new BatchWriteRequest
{
    Database = "",
    Writes = { new Write(), },
    Labels = { { "", "" }, },
};
// Make the request
BatchWriteResponse response = await firestoreClient.BatchWriteAsync(request);

BeginTransaction(BeginTransactionRequest, CallSettings)

public virtual BeginTransactionResponse BeginTransaction(BeginTransactionRequest request, CallSettings callSettings = null)

Starts a new transaction.

Parameters
NameDescription
requestBeginTransactionRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
BeginTransactionResponse

The RPC response.

Example
// Create client
FirestoreClient firestoreClient = FirestoreClient.Create();
// Initialize request argument(s)
BeginTransactionRequest request = new BeginTransactionRequest
{
    Database = "",
    Options = new TransactionOptions(),
};
// Make the request
BeginTransactionResponse response = firestoreClient.BeginTransaction(request);

BeginTransaction(string, CallSettings)

public virtual BeginTransactionResponse BeginTransaction(string database, CallSettings callSettings = null)

Starts a new transaction.

Parameters
NameDescription
databasestring

Required. The database name. In the format: projects/{project_id}/databases/{database_id}.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
BeginTransactionResponse

The RPC response.

Example
// Create client
FirestoreClient firestoreClient = FirestoreClient.Create();
// Initialize request argument(s)
string database = "";
// Make the request
BeginTransactionResponse response = firestoreClient.BeginTransaction(database);

BeginTransactionAsync(BeginTransactionRequest, CallSettings)

public virtual Task<BeginTransactionResponse> BeginTransactionAsync(BeginTransactionRequest request, CallSettings callSettings = null)

Starts a new transaction.

Parameters
NameDescription
requestBeginTransactionRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
TaskBeginTransactionResponse

A Task containing the RPC response.

Example
// Create client
FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();
// Initialize request argument(s)
BeginTransactionRequest request = new BeginTransactionRequest
{
    Database = "",
    Options = new TransactionOptions(),
};
// Make the request
BeginTransactionResponse response = await firestoreClient.BeginTransactionAsync(request);

BeginTransactionAsync(BeginTransactionRequest, CancellationToken)

public virtual Task<BeginTransactionResponse> BeginTransactionAsync(BeginTransactionRequest request, CancellationToken cancellationToken)

Starts a new transaction.

Parameters
NameDescription
requestBeginTransactionRequest

The request object containing all of the parameters for the API call.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
TaskBeginTransactionResponse

A Task containing the RPC response.

Example
// Create client
FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();
// Initialize request argument(s)
BeginTransactionRequest request = new BeginTransactionRequest
{
    Database = "",
    Options = new TransactionOptions(),
};
// Make the request
BeginTransactionResponse response = await firestoreClient.BeginTransactionAsync(request);

BeginTransactionAsync(string, CallSettings)

public virtual Task<BeginTransactionResponse> BeginTransactionAsync(string database, CallSettings callSettings = null)

Starts a new transaction.

Parameters
NameDescription
databasestring

Required. The database name. In the format: projects/{project_id}/databases/{database_id}.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
TaskBeginTransactionResponse

A Task containing the RPC response.

Example
// Create client
FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();
// Initialize request argument(s)
string database = "";
// Make the request
BeginTransactionResponse response = await firestoreClient.BeginTransactionAsync(database);

BeginTransactionAsync(string, CancellationToken)

public virtual Task<BeginTransactionResponse> BeginTransactionAsync(string database, CancellationToken cancellationToken)

Starts a new transaction.

Parameters
NameDescription
databasestring

Required. The database name. In the format: projects/{project_id}/databases/{database_id}.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
TaskBeginTransactionResponse

A Task containing the RPC response.

Example
// Create client
FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();
// Initialize request argument(s)
string database = "";
// Make the request
BeginTransactionResponse response = await firestoreClient.BeginTransactionAsync(database);

Commit(CommitRequest, CallSettings)

public virtual CommitResponse Commit(CommitRequest request, CallSettings callSettings = null)

Commits a transaction, while optionally updating documents.

Parameters
NameDescription
requestCommitRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
CommitResponse

The RPC response.

Example
// Create client
FirestoreClient firestoreClient = FirestoreClient.Create();
// Initialize request argument(s)
CommitRequest request = new CommitRequest
{
    Database = "",
    Writes = { new Write(), },
    Transaction = ByteString.Empty,
};
// Make the request
CommitResponse response = firestoreClient.Commit(request);

Commit(string, IEnumerable<Write>, CallSettings)

public virtual CommitResponse Commit(string database, IEnumerable<Write> writes, CallSettings callSettings = null)

Commits a transaction, while optionally updating documents.

Parameters
NameDescription
databasestring

Required. The database name. In the format: projects/{project_id}/databases/{database_id}.

writesIEnumerableWrite

The writes to apply.

Always executed atomically and in order.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
CommitResponse

The RPC response.

Example
// Create client
FirestoreClient firestoreClient = FirestoreClient.Create();
// Initialize request argument(s)
string database = "";
IEnumerable<Write> writes = new Write[] { new Write(), };
// Make the request
CommitResponse response = firestoreClient.Commit(database, writes);

CommitAsync(CommitRequest, CallSettings)

public virtual Task<CommitResponse> CommitAsync(CommitRequest request, CallSettings callSettings = null)

Commits a transaction, while optionally updating documents.

Parameters
NameDescription
requestCommitRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
TaskCommitResponse

A Task containing the RPC response.

Example
// Create client
FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();
// Initialize request argument(s)
CommitRequest request = new CommitRequest
{
    Database = "",
    Writes = { new Write(), },
    Transaction = ByteString.Empty,
};
// Make the request
CommitResponse response = await firestoreClient.CommitAsync(request);

CommitAsync(CommitRequest, CancellationToken)

public virtual Task<CommitResponse> CommitAsync(CommitRequest request, CancellationToken cancellationToken)

Commits a transaction, while optionally updating documents.

Parameters
NameDescription
requestCommitRequest

The request object containing all of the parameters for the API call.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
TaskCommitResponse

A Task containing the RPC response.

Example
// Create client
FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();
// Initialize request argument(s)
CommitRequest request = new CommitRequest
{
    Database = "",
    Writes = { new Write(), },
    Transaction = ByteString.Empty,
};
// Make the request
CommitResponse response = await firestoreClient.CommitAsync(request);

CommitAsync(string, IEnumerable<Write>, CallSettings)

public virtual Task<CommitResponse> CommitAsync(string database, IEnumerable<Write> writes, CallSettings callSettings = null)

Commits a transaction, while optionally updating documents.

Parameters
NameDescription
databasestring

Required. The database name. In the format: projects/{project_id}/databases/{database_id}.

writesIEnumerableWrite

The writes to apply.

Always executed atomically and in order.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
TaskCommitResponse

A Task containing the RPC response.

Example
// Create client
FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();
// Initialize request argument(s)
string database = "";
IEnumerable<Write> writes = new Write[] { new Write(), };
// Make the request
CommitResponse response = await firestoreClient.CommitAsync(database, writes);

CommitAsync(string, IEnumerable<Write>, CancellationToken)

public virtual Task<CommitResponse> CommitAsync(string database, IEnumerable<Write> writes, CancellationToken cancellationToken)

Commits a transaction, while optionally updating documents.

Parameters
NameDescription
databasestring

Required. The database name. In the format: projects/{project_id}/databases/{database_id}.

writesIEnumerableWrite

The writes to apply.

Always executed atomically and in order.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
TaskCommitResponse

A Task containing the RPC response.

Example
// Create client
FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();
// Initialize request argument(s)
string database = "";
IEnumerable<Write> writes = new Write[] { new Write(), };
// Make the request
CommitResponse response = await firestoreClient.CommitAsync(database, writes);

Create()

public static FirestoreClient Create()

Synchronously creates a FirestoreClient using the default credentials, endpoint and settings. To specify custom credentials or other settings, use FirestoreClientBuilder.

Returns
TypeDescription
FirestoreClient

The created FirestoreClient.

CreateAsync(CancellationToken)

public static Task<FirestoreClient> CreateAsync(CancellationToken cancellationToken = default)

Asynchronously creates a FirestoreClient using the default credentials, endpoint and settings. To specify custom credentials or other settings, use FirestoreClientBuilder.

Parameter
NameDescription
cancellationTokenCancellationToken

The CancellationToken to use while creating the client.

Returns
TypeDescription
TaskFirestoreClient

The task representing the created FirestoreClient.

CreateDocument(CreateDocumentRequest, CallSettings)

public virtual Document CreateDocument(CreateDocumentRequest request, CallSettings callSettings = null)

Creates a new document.

Parameters
NameDescription
requestCreateDocumentRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
Document

The RPC response.

Example
// Create client
FirestoreClient firestoreClient = FirestoreClient.Create();
// Initialize request argument(s)
CreateDocumentRequest request = new CreateDocumentRequest
{
    Parent = "",
    CollectionId = "",
    DocumentId = "",
    Document = new Document(),
    Mask = new DocumentMask(),
};
// Make the request
Document response = firestoreClient.CreateDocument(request);

CreateDocumentAsync(CreateDocumentRequest, CallSettings)

public virtual Task<Document> CreateDocumentAsync(CreateDocumentRequest request, CallSettings callSettings = null)

Creates a new document.

Parameters
NameDescription
requestCreateDocumentRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
TaskDocument

A Task containing the RPC response.

Example
// Create client
FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();
// Initialize request argument(s)
CreateDocumentRequest request = new CreateDocumentRequest
{
    Parent = "",
    CollectionId = "",
    DocumentId = "",
    Document = new Document(),
    Mask = new DocumentMask(),
};
// Make the request
Document response = await firestoreClient.CreateDocumentAsync(request);

CreateDocumentAsync(CreateDocumentRequest, CancellationToken)

public virtual Task<Document> CreateDocumentAsync(CreateDocumentRequest request, CancellationToken cancellationToken)

Creates a new document.

Parameters
NameDescription
requestCreateDocumentRequest

The request object containing all of the parameters for the API call.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
TaskDocument

A Task containing the RPC response.

Example
// Create client
FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();
// Initialize request argument(s)
CreateDocumentRequest request = new CreateDocumentRequest
{
    Parent = "",
    CollectionId = "",
    DocumentId = "",
    Document = new Document(),
    Mask = new DocumentMask(),
};
// Make the request
Document response = await firestoreClient.CreateDocumentAsync(request);

DeleteDocument(DeleteDocumentRequest, CallSettings)

public virtual void DeleteDocument(DeleteDocumentRequest request, CallSettings callSettings = null)

Deletes a document.

Parameters
NameDescription
requestDeleteDocumentRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Example
// Create client
FirestoreClient firestoreClient = FirestoreClient.Create();
// Initialize request argument(s)
DeleteDocumentRequest request = new DeleteDocumentRequest
{
    Name = "",
    CurrentDocument = new Precondition(),
};
// Make the request
firestoreClient.DeleteDocument(request);

DeleteDocument(string, CallSettings)

public virtual void DeleteDocument(string name, CallSettings callSettings = null)

Deletes a document.

Parameters
NameDescription
namestring

Required. The resource name of the Document to delete. In the format: projects/{project_id}/databases/{database_id}/documents/{document_path}.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Example
// Create client
FirestoreClient firestoreClient = FirestoreClient.Create();
// Initialize request argument(s)
string name = "";
// Make the request
firestoreClient.DeleteDocument(name);

DeleteDocumentAsync(DeleteDocumentRequest, CallSettings)

public virtual Task DeleteDocumentAsync(DeleteDocumentRequest request, CallSettings callSettings = null)

Deletes a document.

Parameters
NameDescription
requestDeleteDocumentRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
Task

A Task containing the RPC response.

Example
// Create client
FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();
// Initialize request argument(s)
DeleteDocumentRequest request = new DeleteDocumentRequest
{
    Name = "",
    CurrentDocument = new Precondition(),
};
// Make the request
await firestoreClient.DeleteDocumentAsync(request);

DeleteDocumentAsync(DeleteDocumentRequest, CancellationToken)

public virtual Task DeleteDocumentAsync(DeleteDocumentRequest request, CancellationToken cancellationToken)

Deletes a document.

Parameters
NameDescription
requestDeleteDocumentRequest

The request object containing all of the parameters for the API call.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
Task

A Task containing the RPC response.

Example
// Create client
FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();
// Initialize request argument(s)
DeleteDocumentRequest request = new DeleteDocumentRequest
{
    Name = "",
    CurrentDocument = new Precondition(),
};
// Make the request
await firestoreClient.DeleteDocumentAsync(request);

DeleteDocumentAsync(string, CallSettings)

public virtual Task DeleteDocumentAsync(string name, CallSettings callSettings = null)

Deletes a document.

Parameters
NameDescription
namestring

Required. The resource name of the Document to delete. In the format: projects/{project_id}/databases/{database_id}/documents/{document_path}.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
Task

A Task containing the RPC response.

Example
// Create client
FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();
// Initialize request argument(s)
string name = "";
// Make the request
await firestoreClient.DeleteDocumentAsync(name);

DeleteDocumentAsync(string, CancellationToken)

public virtual Task DeleteDocumentAsync(string name, CancellationToken cancellationToken)

Deletes a document.

Parameters
NameDescription
namestring

Required. The resource name of the Document to delete. In the format: projects/{project_id}/databases/{database_id}/documents/{document_path}.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
Task

A Task containing the RPC response.

Example
// Create client
FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();
// Initialize request argument(s)
string name = "";
// Make the request
await firestoreClient.DeleteDocumentAsync(name);

GetDocument(GetDocumentRequest, CallSettings)

public virtual Document GetDocument(GetDocumentRequest request, CallSettings callSettings = null)

Gets a single document.

Parameters
NameDescription
requestGetDocumentRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
Document

The RPC response.

Example
// Create client
FirestoreClient firestoreClient = FirestoreClient.Create();
// Initialize request argument(s)
GetDocumentRequest request = new GetDocumentRequest
{
    Name = "",
    Mask = new DocumentMask(),
    Transaction = ByteString.Empty,
};
// Make the request
Document response = firestoreClient.GetDocument(request);

GetDocumentAsync(GetDocumentRequest, CallSettings)

public virtual Task<Document> GetDocumentAsync(GetDocumentRequest request, CallSettings callSettings = null)

Gets a single document.

Parameters
NameDescription
requestGetDocumentRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
TaskDocument

A Task containing the RPC response.

Example
// Create client
FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();
// Initialize request argument(s)
GetDocumentRequest request = new GetDocumentRequest
{
    Name = "",
    Mask = new DocumentMask(),
    Transaction = ByteString.Empty,
};
// Make the request
Document response = await firestoreClient.GetDocumentAsync(request);

GetDocumentAsync(GetDocumentRequest, CancellationToken)

public virtual Task<Document> GetDocumentAsync(GetDocumentRequest request, CancellationToken cancellationToken)

Gets a single document.

Parameters
NameDescription
requestGetDocumentRequest

The request object containing all of the parameters for the API call.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
TaskDocument

A Task containing the RPC response.

Example
// Create client
FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();
// Initialize request argument(s)
GetDocumentRequest request = new GetDocumentRequest
{
    Name = "",
    Mask = new DocumentMask(),
    Transaction = ByteString.Empty,
};
// Make the request
Document response = await firestoreClient.GetDocumentAsync(request);

ListCollectionIds(ListCollectionIdsRequest, CallSettings)

public virtual PagedEnumerable<ListCollectionIdsResponse, string> ListCollectionIds(ListCollectionIdsRequest request, CallSettings callSettings = null)

Lists all the collection IDs underneath a document.

Parameters
NameDescription
requestListCollectionIdsRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
PagedEnumerableListCollectionIdsResponsestring

A pageable sequence of string resources.

Example
// Create client
FirestoreClient firestoreClient = FirestoreClient.Create();
// Initialize request argument(s)
ListCollectionIdsRequest request = new ListCollectionIdsRequest
{
    Parent = "",
    ReadTime = new Timestamp(),
};
// Make the request
PagedEnumerable<ListCollectionIdsResponse, string> response = firestoreClient.ListCollectionIds(request);

// Iterate over all response items, lazily performing RPCs as required
foreach (string item in response)
{
    // Do something with each item
    Console.WriteLine(item);
}

// Or iterate over pages (of server-defined size), performing one RPC per page
foreach (ListCollectionIdsResponse page in response.AsRawResponses())
{
    // Do something with each page of items
    Console.WriteLine("A page of results:");
    foreach (string item in page)
    {
        // Do something with each item
        Console.WriteLine(item);
    }
}

// Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
int pageSize = 10;
Page<string> singlePage = response.ReadPage(pageSize);
// Do something with the page of items
Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
foreach (string item in singlePage)
{
    // Do something with each item
    Console.WriteLine(item);
}
// Store the pageToken, for when the next page is required.
string nextPageToken = singlePage.NextPageToken;

ListCollectionIds(string, string, int?, CallSettings)

public virtual PagedEnumerable<ListCollectionIdsResponse, string> ListCollectionIds(string parent, string pageToken = null, int? pageSize = null, CallSettings callSettings = null)

Lists all the collection IDs underneath a document.

Parameters
NameDescription
parentstring

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

pageTokenstring

The token returned from the previous request. A value of null or an empty string retrieves the first page.

pageSizeint

The size of page to request. The response will not be larger than this, but may be smaller. A value of null or 0 uses a server-defined page size.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
PagedEnumerableListCollectionIdsResponsestring

A pageable sequence of string resources.

Example
// Create client
FirestoreClient firestoreClient = FirestoreClient.Create();
// Initialize request argument(s)
string parent = "";
// Make the request
PagedEnumerable<ListCollectionIdsResponse, string> response = firestoreClient.ListCollectionIds(parent);

// Iterate over all response items, lazily performing RPCs as required
foreach (string item in response)
{
    // Do something with each item
    Console.WriteLine(item);
}

// Or iterate over pages (of server-defined size), performing one RPC per page
foreach (ListCollectionIdsResponse page in response.AsRawResponses())
{
    // Do something with each page of items
    Console.WriteLine("A page of results:");
    foreach (string item in page)
    {
        // Do something with each item
        Console.WriteLine(item);
    }
}

// Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
int pageSize = 10;
Page<string> singlePage = response.ReadPage(pageSize);
// Do something with the page of items
Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
foreach (string item in singlePage)
{
    // Do something with each item
    Console.WriteLine(item);
}
// Store the pageToken, for when the next page is required.
string nextPageToken = singlePage.NextPageToken;

ListCollectionIdsAsync(ListCollectionIdsRequest, CallSettings)

public virtual PagedAsyncEnumerable<ListCollectionIdsResponse, string> ListCollectionIdsAsync(ListCollectionIdsRequest request, CallSettings callSettings = null)

Lists all the collection IDs underneath a document.

Parameters
NameDescription
requestListCollectionIdsRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
PagedAsyncEnumerableListCollectionIdsResponsestring

A pageable asynchronous sequence of string resources.

Example
// Create client
FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();
// Initialize request argument(s)
ListCollectionIdsRequest request = new ListCollectionIdsRequest
{
    Parent = "",
    ReadTime = new Timestamp(),
};
// Make the request
PagedAsyncEnumerable<ListCollectionIdsResponse, string> response = firestoreClient.ListCollectionIdsAsync(request);

// Iterate over all response items, lazily performing RPCs as required
await response.ForEachAsync((string item) =>
{
    // Do something with each item
    Console.WriteLine(item);
});

// Or iterate over pages (of server-defined size), performing one RPC per page
await response.AsRawResponses().ForEachAsync((ListCollectionIdsResponse page) =>
{
    // Do something with each page of items
    Console.WriteLine("A page of results:");
    foreach (string item in page)
    {
        // Do something with each item
        Console.WriteLine(item);
    }
});

// Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
int pageSize = 10;
Page<string> singlePage = await response.ReadPageAsync(pageSize);
// Do something with the page of items
Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
foreach (string item in singlePage)
{
    // Do something with each item
    Console.WriteLine(item);
}
// Store the pageToken, for when the next page is required.
string nextPageToken = singlePage.NextPageToken;

ListCollectionIdsAsync(string, string, int?, CallSettings)

public virtual PagedAsyncEnumerable<ListCollectionIdsResponse, string> ListCollectionIdsAsync(string parent, string pageToken = null, int? pageSize = null, CallSettings callSettings = null)

Lists all the collection IDs underneath a document.

Parameters
NameDescription
parentstring

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

pageTokenstring

The token returned from the previous request. A value of null or an empty string retrieves the first page.

pageSizeint

The size of page to request. The response will not be larger than this, but may be smaller. A value of null or 0 uses a server-defined page size.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
PagedAsyncEnumerableListCollectionIdsResponsestring

A pageable asynchronous sequence of string resources.

Example
// Create client
FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();
// Initialize request argument(s)
string parent = "";
// Make the request
PagedAsyncEnumerable<ListCollectionIdsResponse, string> response = firestoreClient.ListCollectionIdsAsync(parent);

// Iterate over all response items, lazily performing RPCs as required
await response.ForEachAsync((string item) =>
{
    // Do something with each item
    Console.WriteLine(item);
});

// Or iterate over pages (of server-defined size), performing one RPC per page
await response.AsRawResponses().ForEachAsync((ListCollectionIdsResponse page) =>
{
    // Do something with each page of items
    Console.WriteLine("A page of results:");
    foreach (string item in page)
    {
        // Do something with each item
        Console.WriteLine(item);
    }
});

// Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
int pageSize = 10;
Page<string> singlePage = await response.ReadPageAsync(pageSize);
// Do something with the page of items
Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
foreach (string item in singlePage)
{
    // Do something with each item
    Console.WriteLine(item);
}
// Store the pageToken, for when the next page is required.
string nextPageToken = singlePage.NextPageToken;

ListDocuments(ListDocumentsRequest, CallSettings)

public virtual PagedEnumerable<ListDocumentsResponse, Document> ListDocuments(ListDocumentsRequest request, CallSettings callSettings = null)

Lists documents.

Parameters
NameDescription
requestListDocumentsRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
PagedEnumerableListDocumentsResponseDocument

A pageable sequence of Document resources.

Example
// Create client
FirestoreClient firestoreClient = FirestoreClient.Create();
// Initialize request argument(s)
ListDocumentsRequest request = new ListDocumentsRequest
{
    Parent = "",
    CollectionId = "",
    OrderBy = "",
    Mask = new DocumentMask(),
    Transaction = ByteString.Empty,
    ShowMissing = false,
};
// Make the request
PagedEnumerable<ListDocumentsResponse, Document> response = firestoreClient.ListDocuments(request);

// Iterate over all response items, lazily performing RPCs as required
foreach (Document item in response)
{
    // Do something with each item
    Console.WriteLine(item);
}

// Or iterate over pages (of server-defined size), performing one RPC per page
foreach (ListDocumentsResponse page in response.AsRawResponses())
{
    // Do something with each page of items
    Console.WriteLine("A page of results:");
    foreach (Document item in page)
    {
        // Do something with each item
        Console.WriteLine(item);
    }
}

// Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
int pageSize = 10;
Page<Document> singlePage = response.ReadPage(pageSize);
// Do something with the page of items
Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
foreach (Document item in singlePage)
{
    // Do something with each item
    Console.WriteLine(item);
}
// Store the pageToken, for when the next page is required.
string nextPageToken = singlePage.NextPageToken;

ListDocumentsAsync(ListDocumentsRequest, CallSettings)

public virtual PagedAsyncEnumerable<ListDocumentsResponse, Document> ListDocumentsAsync(ListDocumentsRequest request, CallSettings callSettings = null)

Lists documents.

Parameters
NameDescription
requestListDocumentsRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
PagedAsyncEnumerableListDocumentsResponseDocument

A pageable asynchronous sequence of Document resources.

Example
// Create client
FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();
// Initialize request argument(s)
ListDocumentsRequest request = new ListDocumentsRequest
{
    Parent = "",
    CollectionId = "",
    OrderBy = "",
    Mask = new DocumentMask(),
    Transaction = ByteString.Empty,
    ShowMissing = false,
};
// Make the request
PagedAsyncEnumerable<ListDocumentsResponse, Document> response = firestoreClient.ListDocumentsAsync(request);

// Iterate over all response items, lazily performing RPCs as required
await response.ForEachAsync((Document item) =>
{
    // Do something with each item
    Console.WriteLine(item);
});

// Or iterate over pages (of server-defined size), performing one RPC per page
await response.AsRawResponses().ForEachAsync((ListDocumentsResponse page) =>
{
    // Do something with each page of items
    Console.WriteLine("A page of results:");
    foreach (Document item in page)
    {
        // Do something with each item
        Console.WriteLine(item);
    }
});

// Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
int pageSize = 10;
Page<Document> singlePage = await response.ReadPageAsync(pageSize);
// Do something with the page of items
Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
foreach (Document item in singlePage)
{
    // Do something with each item
    Console.WriteLine(item);
}
// Store the pageToken, for when the next page is required.
string nextPageToken = singlePage.NextPageToken;

Listen(CallSettings, BidirectionalStreamingSettings)

public virtual FirestoreClient.ListenStream Listen(CallSettings callSettings = null, BidirectionalStreamingSettings streamingSettings = null)

Listens to changes. This method is only available via gRPC or WebChannel (not REST).

Parameters
NameDescription
callSettingsCallSettings

If not null, applies overrides to this RPC call.

streamingSettingsBidirectionalStreamingSettings

If not null, applies streaming overrides to this RPC call.

Returns
TypeDescription
FirestoreClientListenStream

The client-server stream.

Example
// Create client
FirestoreClient firestoreClient = FirestoreClient.Create();
// Initialize streaming call, retrieving the stream object
using FirestoreClient.ListenStream response = firestoreClient.Listen();

// Sending requests and retrieving responses can be arbitrarily interleaved
// Exact sequence will depend on client/server behavior

// Create task to do something with responses from server
Task responseHandlerTask = Task.Run(async () =>
{
    // Note that C# 8 code can use await foreach
    AsyncResponseStream<ListenResponse> responseStream = response.GetResponseStream();
    while (await responseStream.MoveNextAsync())
    {
        ListenResponse responseItem = responseStream.Current;
        // Do something with streamed response
    }
    // The response stream has completed
});

// Send requests to the server
bool done = false;
while (!done)
{
    // Initialize a request
    ListenRequest request = new ListenRequest
    {
        Database = "",
        AddTarget = new Target(),
        Labels = { { "", "" }, },
    };
    // Stream a request to the server
    await response.WriteAsync(request);
    // Set "done" to true when sending requests is complete
}

// Complete writing requests to the stream
await response.WriteCompleteAsync();
// Await the response handler
// This will complete once all server responses have been processed
await responseHandlerTask;

PartitionQuery(PartitionQueryRequest, CallSettings)

public virtual PagedEnumerable<PartitionQueryResponse, Cursor> PartitionQuery(PartitionQueryRequest request, CallSettings callSettings = null)

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.

Parameters
NameDescription
requestPartitionQueryRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
PagedEnumerablePartitionQueryResponseCursor

A pageable sequence of Cursor resources.

Example
// Create client
FirestoreClient firestoreClient = FirestoreClient.Create();
// Initialize request argument(s)
PartitionQueryRequest request = new PartitionQueryRequest
{
    Parent = "",
    StructuredQuery = new StructuredQuery(),
    PartitionCount = 0L,
    ReadTime = new Timestamp(),
};
// Make the request
PagedEnumerable<PartitionQueryResponse, Cursor> response = firestoreClient.PartitionQuery(request);

// Iterate over all response items, lazily performing RPCs as required
foreach (Cursor item in response)
{
    // Do something with each item
    Console.WriteLine(item);
}

// Or iterate over pages (of server-defined size), performing one RPC per page
foreach (PartitionQueryResponse page in response.AsRawResponses())
{
    // Do something with each page of items
    Console.WriteLine("A page of results:");
    foreach (Cursor item in page)
    {
        // Do something with each item
        Console.WriteLine(item);
    }
}

// Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
int pageSize = 10;
Page<Cursor> singlePage = response.ReadPage(pageSize);
// Do something with the page of items
Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
foreach (Cursor item in singlePage)
{
    // Do something with each item
    Console.WriteLine(item);
}
// Store the pageToken, for when the next page is required.
string nextPageToken = singlePage.NextPageToken;

PartitionQueryAsync(PartitionQueryRequest, CallSettings)

public virtual PagedAsyncEnumerable<PartitionQueryResponse, Cursor> PartitionQueryAsync(PartitionQueryRequest request, CallSettings callSettings = null)

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.

Parameters
NameDescription
requestPartitionQueryRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
PagedAsyncEnumerablePartitionQueryResponseCursor

A pageable asynchronous sequence of Cursor resources.

Example
// Create client
FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();
// Initialize request argument(s)
PartitionQueryRequest request = new PartitionQueryRequest
{
    Parent = "",
    StructuredQuery = new StructuredQuery(),
    PartitionCount = 0L,
    ReadTime = new Timestamp(),
};
// Make the request
PagedAsyncEnumerable<PartitionQueryResponse, Cursor> response = firestoreClient.PartitionQueryAsync(request);

// Iterate over all response items, lazily performing RPCs as required
await response.ForEachAsync((Cursor item) =>
{
    // Do something with each item
    Console.WriteLine(item);
});

// Or iterate over pages (of server-defined size), performing one RPC per page
await response.AsRawResponses().ForEachAsync((PartitionQueryResponse page) =>
{
    // Do something with each page of items
    Console.WriteLine("A page of results:");
    foreach (Cursor item in page)
    {
        // Do something with each item
        Console.WriteLine(item);
    }
});

// Or retrieve a single page of known size (unless it's the final page), performing as many RPCs as required
int pageSize = 10;
Page<Cursor> singlePage = await response.ReadPageAsync(pageSize);
// Do something with the page of items
Console.WriteLine($"A page of {pageSize} results (unless it's the final page):");
foreach (Cursor item in singlePage)
{
    // Do something with each item
    Console.WriteLine(item);
}
// Store the pageToken, for when the next page is required.
string nextPageToken = singlePage.NextPageToken;

Rollback(RollbackRequest, CallSettings)

public virtual void Rollback(RollbackRequest request, CallSettings callSettings = null)

Rolls back a transaction.

Parameters
NameDescription
requestRollbackRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Example
// Create client
FirestoreClient firestoreClient = FirestoreClient.Create();
// Initialize request argument(s)
RollbackRequest request = new RollbackRequest
{
    Database = "",
    Transaction = ByteString.Empty,
};
// Make the request
firestoreClient.Rollback(request);

Rollback(string, ByteString, CallSettings)

public virtual void Rollback(string database, ByteString transaction, CallSettings callSettings = null)

Rolls back a transaction.

Parameters
NameDescription
databasestring

Required. The database name. In the format: projects/{project_id}/databases/{database_id}.

transactionByteString

Required. The transaction to roll back.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Example
// Create client
FirestoreClient firestoreClient = FirestoreClient.Create();
// Initialize request argument(s)
string database = "";
ByteString transaction = ByteString.Empty;
// Make the request
firestoreClient.Rollback(database, transaction);

RollbackAsync(RollbackRequest, CallSettings)

public virtual Task RollbackAsync(RollbackRequest request, CallSettings callSettings = null)

Rolls back a transaction.

Parameters
NameDescription
requestRollbackRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
Task

A Task containing the RPC response.

Example
// Create client
FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();
// Initialize request argument(s)
RollbackRequest request = new RollbackRequest
{
    Database = "",
    Transaction = ByteString.Empty,
};
// Make the request
await firestoreClient.RollbackAsync(request);

RollbackAsync(RollbackRequest, CancellationToken)

public virtual Task RollbackAsync(RollbackRequest request, CancellationToken cancellationToken)

Rolls back a transaction.

Parameters
NameDescription
requestRollbackRequest

The request object containing all of the parameters for the API call.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
Task

A Task containing the RPC response.

Example
// Create client
FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();
// Initialize request argument(s)
RollbackRequest request = new RollbackRequest
{
    Database = "",
    Transaction = ByteString.Empty,
};
// Make the request
await firestoreClient.RollbackAsync(request);

RollbackAsync(string, ByteString, CallSettings)

public virtual Task RollbackAsync(string database, ByteString transaction, CallSettings callSettings = null)

Rolls back a transaction.

Parameters
NameDescription
databasestring

Required. The database name. In the format: projects/{project_id}/databases/{database_id}.

transactionByteString

Required. The transaction to roll back.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
Task

A Task containing the RPC response.

Example
// Create client
FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();
// Initialize request argument(s)
string database = "";
ByteString transaction = ByteString.Empty;
// Make the request
await firestoreClient.RollbackAsync(database, transaction);

RollbackAsync(string, ByteString, CancellationToken)

public virtual Task RollbackAsync(string database, ByteString transaction, CancellationToken cancellationToken)

Rolls back a transaction.

Parameters
NameDescription
databasestring

Required. The database name. In the format: projects/{project_id}/databases/{database_id}.

transactionByteString

Required. The transaction to roll back.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
Task

A Task containing the RPC response.

Example
// Create client
FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();
// Initialize request argument(s)
string database = "";
ByteString transaction = ByteString.Empty;
// Make the request
await firestoreClient.RollbackAsync(database, transaction);

RunAggregationQuery(RunAggregationQueryRequest, CallSettings)

public virtual FirestoreClient.RunAggregationQueryStream RunAggregationQuery(RunAggregationQueryRequest request, CallSettings callSettings = null)

Runs an aggregation query.

Rather than producing [Document][google.firestore.v1.Document] results like [Firestore.RunQuery][google.firestore.v1.Firestore.RunQuery], this API allows running an aggregation to produce a series of [AggregationResult][google.firestore.v1.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 );
Parameters
NameDescription
requestRunAggregationQueryRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
FirestoreClientRunAggregationQueryStream

The server stream.

Example
// Create client
FirestoreClient firestoreClient = FirestoreClient.Create();
// Initialize request argument(s)
RunAggregationQueryRequest request = new RunAggregationQueryRequest
{
    Parent = "",
    StructuredAggregationQuery = new StructuredAggregationQuery(),
    Transaction = ByteString.Empty,
    ExplainOptions = new ExplainOptions(),
};
// Make the request, returning a streaming response
using FirestoreClient.RunAggregationQueryStream response = firestoreClient.RunAggregationQuery(request);

// Read streaming responses from server until complete
// Note that C# 8 code can use await foreach
AsyncResponseStream<RunAggregationQueryResponse> responseStream = response.GetResponseStream();
while (await responseStream.MoveNextAsync())
{
    RunAggregationQueryResponse responseItem = responseStream.Current;
    // Do something with streamed response
}
// The response stream has completed

RunQuery(RunQueryRequest, CallSettings)

public virtual FirestoreClient.RunQueryStream RunQuery(RunQueryRequest request, CallSettings callSettings = null)

Runs a query.

Parameters
NameDescription
requestRunQueryRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
FirestoreClientRunQueryStream

The server stream.

Example
// Create client
FirestoreClient firestoreClient = FirestoreClient.Create();
// Initialize request argument(s)
RunQueryRequest request = new RunQueryRequest
{
    Parent = "",
    StructuredQuery = new StructuredQuery(),
    Transaction = ByteString.Empty,
    ExplainOptions = new ExplainOptions(),
};
// Make the request, returning a streaming response
using FirestoreClient.RunQueryStream response = firestoreClient.RunQuery(request);

// Read streaming responses from server until complete
// Note that C# 8 code can use await foreach
AsyncResponseStream<RunQueryResponse> responseStream = response.GetResponseStream();
while (await responseStream.MoveNextAsync())
{
    RunQueryResponse responseItem = responseStream.Current;
    // Do something with streamed response
}
// The response stream has completed

ShutdownDefaultChannelsAsync()

public static Task ShutdownDefaultChannelsAsync()

Shuts down any channels automatically created by Create() and CreateAsync(CancellationToken). Channels which weren't automatically created are not affected.

Returns
TypeDescription
Task

A task representing the asynchronous shutdown operation.

Remarks

After calling this method, further calls to Create() and CreateAsync(CancellationToken) will create new channels, which could in turn be shut down by another call to this method.

UpdateDocument(Document, DocumentMask, CallSettings)

public virtual Document UpdateDocument(Document document, DocumentMask updateMask, CallSettings callSettings = null)

Updates or inserts a document.

Parameters
NameDescription
documentDocument

Required. The updated document. Creates the document if it does not already exist.

updateMaskDocumentMask

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.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
Document

The RPC response.

Example
// Create client
FirestoreClient firestoreClient = FirestoreClient.Create();
// Initialize request argument(s)
Document document = new Document();
DocumentMask updateMask = new DocumentMask();
// Make the request
Document response = firestoreClient.UpdateDocument(document, updateMask);

UpdateDocument(UpdateDocumentRequest, CallSettings)

public virtual Document UpdateDocument(UpdateDocumentRequest request, CallSettings callSettings = null)

Updates or inserts a document.

Parameters
NameDescription
requestUpdateDocumentRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
Document

The RPC response.

Example
// Create client
FirestoreClient firestoreClient = FirestoreClient.Create();
// Initialize request argument(s)
UpdateDocumentRequest request = new UpdateDocumentRequest
{
    Document = new Document(),
    UpdateMask = new DocumentMask(),
    Mask = new DocumentMask(),
    CurrentDocument = new Precondition(),
};
// Make the request
Document response = firestoreClient.UpdateDocument(request);

UpdateDocumentAsync(Document, DocumentMask, CallSettings)

public virtual Task<Document> UpdateDocumentAsync(Document document, DocumentMask updateMask, CallSettings callSettings = null)

Updates or inserts a document.

Parameters
NameDescription
documentDocument

Required. The updated document. Creates the document if it does not already exist.

updateMaskDocumentMask

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.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
TaskDocument

A Task containing the RPC response.

Example
// Create client
FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();
// Initialize request argument(s)
Document document = new Document();
DocumentMask updateMask = new DocumentMask();
// Make the request
Document response = await firestoreClient.UpdateDocumentAsync(document, updateMask);

UpdateDocumentAsync(Document, DocumentMask, CancellationToken)

public virtual Task<Document> UpdateDocumentAsync(Document document, DocumentMask updateMask, CancellationToken cancellationToken)

Updates or inserts a document.

Parameters
NameDescription
documentDocument

Required. The updated document. Creates the document if it does not already exist.

updateMaskDocumentMask

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.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
TaskDocument

A Task containing the RPC response.

Example
// Create client
FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();
// Initialize request argument(s)
Document document = new Document();
DocumentMask updateMask = new DocumentMask();
// Make the request
Document response = await firestoreClient.UpdateDocumentAsync(document, updateMask);

UpdateDocumentAsync(UpdateDocumentRequest, CallSettings)

public virtual Task<Document> UpdateDocumentAsync(UpdateDocumentRequest request, CallSettings callSettings = null)

Updates or inserts a document.

Parameters
NameDescription
requestUpdateDocumentRequest

The request object containing all of the parameters for the API call.

callSettingsCallSettings

If not null, applies overrides to this RPC call.

Returns
TypeDescription
TaskDocument

A Task containing the RPC response.

Example
// Create client
FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();
// Initialize request argument(s)
UpdateDocumentRequest request = new UpdateDocumentRequest
{
    Document = new Document(),
    UpdateMask = new DocumentMask(),
    Mask = new DocumentMask(),
    CurrentDocument = new Precondition(),
};
// Make the request
Document response = await firestoreClient.UpdateDocumentAsync(request);

UpdateDocumentAsync(UpdateDocumentRequest, CancellationToken)

public virtual Task<Document> UpdateDocumentAsync(UpdateDocumentRequest request, CancellationToken cancellationToken)

Updates or inserts a document.

Parameters
NameDescription
requestUpdateDocumentRequest

The request object containing all of the parameters for the API call.

cancellationTokenCancellationToken

A CancellationToken to use for this RPC.

Returns
TypeDescription
TaskDocument

A Task containing the RPC response.

Example
// Create client
FirestoreClient firestoreClient = await FirestoreClient.CreateAsync();
// Initialize request argument(s)
UpdateDocumentRequest request = new UpdateDocumentRequest
{
    Document = new Document(),
    UpdateMask = new DocumentMask(),
    Mask = new DocumentMask(),
    CurrentDocument = new Precondition(),
};
// Make the request
Document response = await firestoreClient.UpdateDocumentAsync(request);

Write(CallSettings, BidirectionalStreamingSettings)

public virtual FirestoreClient.WriteStream Write(CallSettings callSettings = null, BidirectionalStreamingSettings streamingSettings = null)

Streams batches of document updates and deletes, in order. This method is only available via gRPC or WebChannel (not REST).

Parameters
NameDescription
callSettingsCallSettings

If not null, applies overrides to this RPC call.

streamingSettingsBidirectionalStreamingSettings

If not null, applies streaming overrides to this RPC call.

Returns
TypeDescription
FirestoreClientWriteStream

The client-server stream.

Example
// Create client
FirestoreClient firestoreClient = FirestoreClient.Create();
// Initialize streaming call, retrieving the stream object
using FirestoreClient.WriteStream response = firestoreClient.Write();

// Sending requests and retrieving responses can be arbitrarily interleaved
// Exact sequence will depend on client/server behavior

// Create task to do something with responses from server
Task responseHandlerTask = Task.Run(async () =>
{
    // Note that C# 8 code can use await foreach
    AsyncResponseStream<WriteResponse> responseStream = response.GetResponseStream();
    while (await responseStream.MoveNextAsync())
    {
        WriteResponse responseItem = responseStream.Current;
        // Do something with streamed response
    }
    // The response stream has completed
});

// Send requests to the server
bool done = false;
while (!done)
{
    // Initialize a request
    WriteRequest request = new WriteRequest
    {
        Database = "",
        StreamId = "",
        Writes = { new Write(), },
        StreamToken = ByteString.Empty,
        Labels = { { "", "" }, },
    };
    // Stream a request to the server
    await response.WriteAsync(request);
    // Set "done" to true when sending requests is complete
}

// Complete writing requests to the stream
await response.WriteCompleteAsync();
// Await the response handler
// This will complete once all server responses have been processed
await responseHandlerTask;