Package firestore is an auto-generated package for the Cloud Firestore API.
Accesses the NoSQL document database built for automatic scaling, high performance, and ease of application development.
General documentation
For information that is relevant for all client libraries please reference https://pkg.go.dev/cloud.google.com/go#pkg-overview . Some information on this page includes:
- Authentication and Authorization
- Timeouts and Cancellation
- Testing against Client Libraries
- Debugging Client Libraries
- Inspecting errors
Example usage
To get started with this package, create a client.
// go get cloud.google.com/go/firestore/apiv1@latest ctx := context . Background () // This snippet has been automatically generated and should be regarded as a code template only. // It will require modifications to work: // - It may require correct/in-range values for request initialization. // - It may require specifying regional endpoints when creating the service client as shown in: // https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options c , err := firestore . NewClient ( ctx ) if err != nil { // TODO: Handle error. } defer c . Close ()
The client will use your default application credentials. Clients should be reused instead of created as needed. The methods of Client are safe for concurrent use by multiple goroutines. The returned client must be Closed when it is done being used.
Using the Client
The following is an example of making an API call with the newly created client, mentioned above.
Use of Context
The ctx passed to NewClient is used for authentication requests and for creating the underlying connection, but is not used for subsequent calls. Individual methods on the client use the ctx given to them.
To close the open connection, use the Close() method.
Functions
func DefaultAuthScopes
func
DefaultAuthScopes
()
[]
string
DefaultAuthScopes reports the default set of authentication scopes to use with this package.
CallOptions
type
CallOptions
struct
{
GetDocument
[]
gax
.
CallOption
ListDocuments
[]
gax
.
CallOption
UpdateDocument
[]
gax
.
CallOption
DeleteDocument
[]
gax
.
CallOption
BatchGetDocuments
[]
gax
.
CallOption
BeginTransaction
[]
gax
.
CallOption
Commit
[]
gax
.
CallOption
Rollback
[]
gax
.
CallOption
RunQuery
[]
gax
.
CallOption
RunAggregationQuery
[]
gax
.
CallOption
PartitionQuery
[]
gax
.
CallOption
Write
[]
gax
.
CallOption
Listen
[]
gax
.
CallOption
ListCollectionIds
[]
gax
.
CallOption
BatchWrite
[]
gax
.
CallOption
CreateDocument
[]
gax
.
CallOption
CancelOperation
[]
gax
.
CallOption
DeleteOperation
[]
gax
.
CallOption
GetOperation
[]
gax
.
CallOption
ListOperations
[]
gax
.
CallOption
}
CallOptions contains the retry settings for each method of Client.
Client
type
Client
struct
{
// The call options for this service.
CallOptions
*
CallOptions
// contains filtered or unexported fields
}
Client is a client for interacting with Cloud Firestore API. Methods, except Close, may be called concurrently. However, fields must not be modified concurrently with method calls.
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.
func NewClient
NewClient creates a new firestore client based on gRPC. The returned client must be Closed when it is done being used to clean up its underlying connections.
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.
Example
package
main
import
(
"context"
firestore
"cloud.google.com/go/firestore/apiv1"
)
func
main
()
{
ctx
:=
context
.
Background
()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c
,
err
:=
firestore
.
NewClient
(
ctx
)
if
err
!=
nil
{
// TODO: Handle error.
}
defer
c
.
Close
()
// TODO: Use client.
_
=
c
}
func NewRESTClient
NewRESTClient creates a new firestore rest client.
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.
Example
package
main
import
(
"context"
firestore
"cloud.google.com/go/firestore/apiv1"
)
func
main
()
{
ctx
:=
context
.
Background
()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c
,
err
:=
firestore
.
NewRESTClient
(
ctx
)
if
err
!=
nil
{
// TODO: Handle error.
}
defer
c
.
Close
()
// TODO: Use client.
_
=
c
}
func (*Client) BatchGetDocuments
func
(
c
*
Client
)
BatchGetDocuments
(
ctx
context
.
Context
,
req
*
firestorepb
.
BatchGetDocumentsRequest
,
opts
...
gax
.
CallOption
)
(
firestorepb
.
Firestore_BatchGetDocumentsClient
,
error
)
BatchGetDocuments gets multiple documents.
Documents returned by this method are not guaranteed to be returned in the same order that they were requested.
func (*Client) BatchWrite
func
(
c
*
Client
)
BatchWrite
(
ctx
context
.
Context
,
req
*
firestorepb
.
BatchWriteRequest
,
opts
...
gax
.
CallOption
)
(
*
firestorepb
.
BatchWriteResponse
,
error
)
BatchWrite 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.
Example
package
main
import
(
"context"
firestore
"cloud.google.com/go/firestore/apiv1"
firestorepb
"cloud.google.com/go/firestore/apiv1/firestorepb"
)
func
main
()
{
ctx
:=
context
.
Background
()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c
,
err
:=
firestore
.
NewClient
(
ctx
)
if
err
!=
nil
{
// TODO: Handle error.
}
defer
c
.
Close
()
req
:=
& firestorepb
.
BatchWriteRequest
{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/firestore/apiv1/firestorepb#BatchWriteRequest.
}
resp
,
err
:=
c
.
BatchWrite
(
ctx
,
req
)
if
err
!=
nil
{
// TODO: Handle error.
}
// TODO: Use resp.
_
=
resp
}
func (*Client) BeginTransaction
func
(
c
*
Client
)
BeginTransaction
(
ctx
context
.
Context
,
req
*
firestorepb
.
BeginTransactionRequest
,
opts
...
gax
.
CallOption
)
(
*
firestorepb
.
BeginTransactionResponse
,
error
)
BeginTransaction starts a new transaction.
Example
package
main
import
(
"context"
firestore
"cloud.google.com/go/firestore/apiv1"
firestorepb
"cloud.google.com/go/firestore/apiv1/firestorepb"
)
func
main
()
{
ctx
:=
context
.
Background
()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c
,
err
:=
firestore
.
NewClient
(
ctx
)
if
err
!=
nil
{
// TODO: Handle error.
}
defer
c
.
Close
()
req
:=
& firestorepb
.
BeginTransactionRequest
{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/firestore/apiv1/firestorepb#BeginTransactionRequest.
}
resp
,
err
:=
c
.
BeginTransaction
(
ctx
,
req
)
if
err
!=
nil
{
// TODO: Handle error.
}
// TODO: Use resp.
_
=
resp
}
func (*Client) CancelOperation
func
(
c
*
Client
)
CancelOperation
(
ctx
context
.
Context
,
req
*
longrunningpb
.
CancelOperationRequest
,
opts
...
gax
.
CallOption
)
error
CancelOperation is a utility method from google.longrunning.Operations.
Example
package
main
import
(
"context"
firestore
"cloud.google.com/go/firestore/apiv1"
longrunningpb
"cloud.google.com/go/longrunning/autogen/longrunningpb"
)
func
main
()
{
ctx
:=
context
.
Background
()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c
,
err
:=
firestore
.
NewClient
(
ctx
)
if
err
!=
nil
{
// TODO: Handle error.
}
defer
c
.
Close
()
req
:=
& longrunningpb
.
CancelOperationRequest
{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#CancelOperationRequest.
}
err
=
c
.
CancelOperation
(
ctx
,
req
)
if
err
!=
nil
{
// TODO: Handle error.
}
}
func (*Client) Close
Close closes the connection to the API service. The user should invoke this when the client is no longer required.
func (*Client) Commit
func
(
c
*
Client
)
Commit
(
ctx
context
.
Context
,
req
*
firestorepb
.
CommitRequest
,
opts
...
gax
.
CallOption
)
(
*
firestorepb
.
CommitResponse
,
error
)
Commit commits a transaction, while optionally updating documents.
Example
package
main
import
(
"context"
firestore
"cloud.google.com/go/firestore/apiv1"
firestorepb
"cloud.google.com/go/firestore/apiv1/firestorepb"
)
func
main
()
{
ctx
:=
context
.
Background
()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c
,
err
:=
firestore
.
NewClient
(
ctx
)
if
err
!=
nil
{
// TODO: Handle error.
}
defer
c
.
Close
()
req
:=
& firestorepb
.
CommitRequest
{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/firestore/apiv1/firestorepb#CommitRequest.
}
resp
,
err
:=
c
.
Commit
(
ctx
,
req
)
if
err
!=
nil
{
// TODO: Handle error.
}
// TODO: Use resp.
_
=
resp
}
func (*Client) Connection (deprecated)
func
(
c
*
Client
)
Connection
()
*
grpc
.
ClientConn
Connection returns a connection to the API service.
Deprecated: Connections are now pooled so this method does not always return the same resource.
func (*Client) CreateDocument
func
(
c
*
Client
)
CreateDocument
(
ctx
context
.
Context
,
req
*
firestorepb
.
CreateDocumentRequest
,
opts
...
gax
.
CallOption
)
(
*
firestorepb
.
Document
,
error
)
CreateDocument creates a new document.
Example
package
main
import
(
"context"
firestore
"cloud.google.com/go/firestore/apiv1"
firestorepb
"cloud.google.com/go/firestore/apiv1/firestorepb"
)
func
main
()
{
ctx
:=
context
.
Background
()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c
,
err
:=
firestore
.
NewClient
(
ctx
)
if
err
!=
nil
{
// TODO: Handle error.
}
defer
c
.
Close
()
req
:=
& firestorepb
.
CreateDocumentRequest
{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/firestore/apiv1/firestorepb#CreateDocumentRequest.
}
resp
,
err
:=
c
.
CreateDocument
(
ctx
,
req
)
if
err
!=
nil
{
// TODO: Handle error.
}
// TODO: Use resp.
_
=
resp
}
func (*Client) DeleteDocument
func
(
c
*
Client
)
DeleteDocument
(
ctx
context
.
Context
,
req
*
firestorepb
.
DeleteDocumentRequest
,
opts
...
gax
.
CallOption
)
error
DeleteDocument deletes a document.
Example
package
main
import
(
"context"
firestore
"cloud.google.com/go/firestore/apiv1"
firestorepb
"cloud.google.com/go/firestore/apiv1/firestorepb"
)
func
main
()
{
ctx
:=
context
.
Background
()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c
,
err
:=
firestore
.
NewClient
(
ctx
)
if
err
!=
nil
{
// TODO: Handle error.
}
defer
c
.
Close
()
req
:=
& firestorepb
.
DeleteDocumentRequest
{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/firestore/apiv1/firestorepb#DeleteDocumentRequest.
}
err
=
c
.
DeleteDocument
(
ctx
,
req
)
if
err
!=
nil
{
// TODO: Handle error.
}
}
func (*Client) DeleteOperation
func
(
c
*
Client
)
DeleteOperation
(
ctx
context
.
Context
,
req
*
longrunningpb
.
DeleteOperationRequest
,
opts
...
gax
.
CallOption
)
error
DeleteOperation is a utility method from google.longrunning.Operations.
Example
package
main
import
(
"context"
firestore
"cloud.google.com/go/firestore/apiv1"
longrunningpb
"cloud.google.com/go/longrunning/autogen/longrunningpb"
)
func
main
()
{
ctx
:=
context
.
Background
()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c
,
err
:=
firestore
.
NewClient
(
ctx
)
if
err
!=
nil
{
// TODO: Handle error.
}
defer
c
.
Close
()
req
:=
& longrunningpb
.
DeleteOperationRequest
{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#DeleteOperationRequest.
}
err
=
c
.
DeleteOperation
(
ctx
,
req
)
if
err
!=
nil
{
// TODO: Handle error.
}
}
func (*Client) GetDocument
func
(
c
*
Client
)
GetDocument
(
ctx
context
.
Context
,
req
*
firestorepb
.
GetDocumentRequest
,
opts
...
gax
.
CallOption
)
(
*
firestorepb
.
Document
,
error
)
GetDocument gets a single document.
Example
package
main
import
(
"context"
firestore
"cloud.google.com/go/firestore/apiv1"
firestorepb
"cloud.google.com/go/firestore/apiv1/firestorepb"
)
func
main
()
{
ctx
:=
context
.
Background
()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c
,
err
:=
firestore
.
NewClient
(
ctx
)
if
err
!=
nil
{
// TODO: Handle error.
}
defer
c
.
Close
()
req
:=
& firestorepb
.
GetDocumentRequest
{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/firestore/apiv1/firestorepb#GetDocumentRequest.
}
resp
,
err
:=
c
.
GetDocument
(
ctx
,
req
)
if
err
!=
nil
{
// TODO: Handle error.
}
// TODO: Use resp.
_
=
resp
}
func (*Client) GetOperation
func
(
c
*
Client
)
GetOperation
(
ctx
context
.
Context
,
req
*
longrunningpb
.
GetOperationRequest
,
opts
...
gax
.
CallOption
)
(
*
longrunningpb
.
Operation
,
error
)
GetOperation is a utility method from google.longrunning.Operations.
Example
package
main
import
(
"context"
firestore
"cloud.google.com/go/firestore/apiv1"
longrunningpb
"cloud.google.com/go/longrunning/autogen/longrunningpb"
)
func
main
()
{
ctx
:=
context
.
Background
()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c
,
err
:=
firestore
.
NewClient
(
ctx
)
if
err
!=
nil
{
// TODO: Handle error.
}
defer
c
.
Close
()
req
:=
& longrunningpb
.
GetOperationRequest
{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#GetOperationRequest.
}
resp
,
err
:=
c
.
GetOperation
(
ctx
,
req
)
if
err
!=
nil
{
// TODO: Handle error.
}
// TODO: Use resp.
_
=
resp
}
func (*Client) ListCollectionIds
func
(
c
*
Client
)
ListCollectionIds
(
ctx
context
.
Context
,
req
*
firestorepb
.
ListCollectionIdsRequest
,
opts
...
gax
.
CallOption
)
*
StringIterator
ListCollectionIds lists all the collection IDs underneath a document.
Examples
package
main
import
(
"context"
firestore
"cloud.google.com/go/firestore/apiv1"
firestorepb
"cloud.google.com/go/firestore/apiv1/firestorepb"
"google.golang.org/api/iterator"
)
func
main
()
{
ctx
:=
context
.
Background
()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c
,
err
:=
firestore
.
NewClient
(
ctx
)
if
err
!=
nil
{
// TODO: Handle error.
}
defer
c
.
Close
()
req
:=
& firestorepb
.
ListCollectionIdsRequest
{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/firestore/apiv1/firestorepb#ListCollectionIdsRequest.
}
it
:=
c
.
ListCollectionIds
(
ctx
,
req
)
for
{
resp
,
err
:=
it
.
Next
()
if
err
==
iterator
.
Done
{
break
}
if
err
!=
nil
{
// TODO: Handle error.
}
// TODO: Use resp.
_
=
resp
// If you need to access the underlying RPC response,
// you can do so by casting the `Response` as below.
// Otherwise, remove this line. Only populated after
// first call to Next(). Not safe for concurrent access.
_
=
it
.
Response
.(
*
firestorepb
.
ListCollectionIdsResponse
)
}
}
all
package
main
import
(
"context"
firestore
"cloud.google.com/go/firestore/apiv1"
firestorepb
"cloud.google.com/go/firestore/apiv1/firestorepb"
)
func
main
()
{
ctx
:=
context
.
Background
()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c
,
err
:=
firestore
.
NewClient
(
ctx
)
if
err
!=
nil
{
// TODO: Handle error.
}
defer
c
.
Close
()
req
:=
& firestorepb
.
ListCollectionIdsRequest
{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/firestore/apiv1/firestorepb#ListCollectionIdsRequest.
}
for
resp
,
err
:=
range
c
.
ListCollectionIds
(
ctx
,
req
).
All
()
{
if
err
!=
nil
{
// TODO: Handle error and break/return/continue. Iteration will stop after any error.
}
// TODO: Use resp.
_
=
resp
}
}
func (*Client) ListDocuments
func
(
c
*
Client
)
ListDocuments
(
ctx
context
.
Context
,
req
*
firestorepb
.
ListDocumentsRequest
,
opts
...
gax
.
CallOption
)
*
DocumentIterator
ListDocuments lists documents.
Examples
package
main
import
(
"context"
firestore
"cloud.google.com/go/firestore/apiv1"
firestorepb
"cloud.google.com/go/firestore/apiv1/firestorepb"
"google.golang.org/api/iterator"
)
func
main
()
{
ctx
:=
context
.
Background
()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c
,
err
:=
firestore
.
NewClient
(
ctx
)
if
err
!=
nil
{
// TODO: Handle error.
}
defer
c
.
Close
()
req
:=
& firestorepb
.
ListDocumentsRequest
{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/firestore/apiv1/firestorepb#ListDocumentsRequest.
}
it
:=
c
.
ListDocuments
(
ctx
,
req
)
for
{
resp
,
err
:=
it
.
Next
()
if
err
==
iterator
.
Done
{
break
}
if
err
!=
nil
{
// TODO: Handle error.
}
// TODO: Use resp.
_
=
resp
// If you need to access the underlying RPC response,
// you can do so by casting the `Response` as below.
// Otherwise, remove this line. Only populated after
// first call to Next(). Not safe for concurrent access.
_
=
it
.
Response
.(
*
firestorepb
.
ListDocumentsResponse
)
}
}
all
package
main
import
(
"context"
firestore
"cloud.google.com/go/firestore/apiv1"
firestorepb
"cloud.google.com/go/firestore/apiv1/firestorepb"
)
func
main
()
{
ctx
:=
context
.
Background
()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c
,
err
:=
firestore
.
NewClient
(
ctx
)
if
err
!=
nil
{
// TODO: Handle error.
}
defer
c
.
Close
()
req
:=
& firestorepb
.
ListDocumentsRequest
{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/firestore/apiv1/firestorepb#ListDocumentsRequest.
}
for
resp
,
err
:=
range
c
.
ListDocuments
(
ctx
,
req
).
All
()
{
if
err
!=
nil
{
// TODO: Handle error and break/return/continue. Iteration will stop after any error.
}
// TODO: Use resp.
_
=
resp
}
}
func (*Client) ListOperations
func
(
c
*
Client
)
ListOperations
(
ctx
context
.
Context
,
req
*
longrunningpb
.
ListOperationsRequest
,
opts
...
gax
.
CallOption
)
*
OperationIterator
ListOperations is a utility method from google.longrunning.Operations.
Examples
package
main
import
(
"context"
firestore
"cloud.google.com/go/firestore/apiv1"
longrunningpb
"cloud.google.com/go/longrunning/autogen/longrunningpb"
"google.golang.org/api/iterator"
)
func
main
()
{
ctx
:=
context
.
Background
()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c
,
err
:=
firestore
.
NewClient
(
ctx
)
if
err
!=
nil
{
// TODO: Handle error.
}
defer
c
.
Close
()
req
:=
& longrunningpb
.
ListOperationsRequest
{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#ListOperationsRequest.
}
it
:=
c
.
ListOperations
(
ctx
,
req
)
for
{
resp
,
err
:=
it
.
Next
()
if
err
==
iterator
.
Done
{
break
}
if
err
!=
nil
{
// TODO: Handle error.
}
// TODO: Use resp.
_
=
resp
// If you need to access the underlying RPC response,
// you can do so by casting the `Response` as below.
// Otherwise, remove this line. Only populated after
// first call to Next(). Not safe for concurrent access.
_
=
it
.
Response
.(
*
longrunningpb
.
ListOperationsResponse
)
}
}
all
package
main
import
(
"context"
firestore
"cloud.google.com/go/firestore/apiv1"
longrunningpb
"cloud.google.com/go/longrunning/autogen/longrunningpb"
)
func
main
()
{
ctx
:=
context
.
Background
()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c
,
err
:=
firestore
.
NewClient
(
ctx
)
if
err
!=
nil
{
// TODO: Handle error.
}
defer
c
.
Close
()
req
:=
& longrunningpb
.
ListOperationsRequest
{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/longrunning/autogen/longrunningpb#ListOperationsRequest.
}
for
resp
,
err
:=
range
c
.
ListOperations
(
ctx
,
req
).
All
()
{
if
err
!=
nil
{
// TODO: Handle error and break/return/continue. Iteration will stop after any error.
}
// TODO: Use resp.
_
=
resp
}
}
func (*Client) Listen
func
(
c
*
Client
)
Listen
(
ctx
context
.
Context
,
opts
...
gax
.
CallOption
)
(
firestorepb
.
Firestore_ListenClient
,
error
)
Listen listens to changes. This method is only available via gRPC or WebChannel (not REST).
This method is not supported for the REST transport.
Example
package
main
import
(
"context"
"io"
firestore
"cloud.google.com/go/firestore/apiv1"
firestorepb
"cloud.google.com/go/firestore/apiv1/firestorepb"
)
func
main
()
{
ctx
:=
context
.
Background
()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c
,
err
:=
firestore
.
NewClient
(
ctx
)
if
err
!=
nil
{
// TODO: Handle error.
}
defer
c
.
Close
()
stream
,
err
:=
c
.
Listen
(
ctx
)
if
err
!=
nil
{
// TODO: Handle error.
}
go
func
()
{
reqs
:=
[]
*
firestorepb
.
ListenRequest
{
// TODO: Create requests.
}
for
_
,
req
:=
range
reqs
{
if
err
:=
stream
.
Send
(
req
);
err
!=
nil
{
// TODO: Handle error.
}
}
stream
.
CloseSend
()
}()
for
{
resp
,
err
:=
stream
.
Recv
()
if
err
==
io
.
EOF
{
break
}
if
err
!=
nil
{
// TODO: handle error.
}
// TODO: Use resp.
_
=
resp
}
}
func (*Client) PartitionQuery
func
(
c
*
Client
)
PartitionQuery
(
ctx
context
.
Context
,
req
*
firestorepb
.
PartitionQueryRequest
,
opts
...
gax
.
CallOption
)
*
CursorIterator
PartitionQuery 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.
Examples
package
main
import
(
"context"
firestore
"cloud.google.com/go/firestore/apiv1"
firestorepb
"cloud.google.com/go/firestore/apiv1/firestorepb"
"google.golang.org/api/iterator"
)
func
main
()
{
ctx
:=
context
.
Background
()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c
,
err
:=
firestore
.
NewClient
(
ctx
)
if
err
!=
nil
{
// TODO: Handle error.
}
defer
c
.
Close
()
req
:=
& firestorepb
.
PartitionQueryRequest
{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/firestore/apiv1/firestorepb#PartitionQueryRequest.
}
it
:=
c
.
PartitionQuery
(
ctx
,
req
)
for
{
resp
,
err
:=
it
.
Next
()
if
err
==
iterator
.
Done
{
break
}
if
err
!=
nil
{
// TODO: Handle error.
}
// TODO: Use resp.
_
=
resp
// If you need to access the underlying RPC response,
// you can do so by casting the `Response` as below.
// Otherwise, remove this line. Only populated after
// first call to Next(). Not safe for concurrent access.
_
=
it
.
Response
.(
*
firestorepb
.
PartitionQueryResponse
)
}
}
all
package
main
import
(
"context"
firestore
"cloud.google.com/go/firestore/apiv1"
firestorepb
"cloud.google.com/go/firestore/apiv1/firestorepb"
)
func
main
()
{
ctx
:=
context
.
Background
()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c
,
err
:=
firestore
.
NewClient
(
ctx
)
if
err
!=
nil
{
// TODO: Handle error.
}
defer
c
.
Close
()
req
:=
& firestorepb
.
PartitionQueryRequest
{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/firestore/apiv1/firestorepb#PartitionQueryRequest.
}
for
resp
,
err
:=
range
c
.
PartitionQuery
(
ctx
,
req
).
All
()
{
if
err
!=
nil
{
// TODO: Handle error and break/return/continue. Iteration will stop after any error.
}
// TODO: Use resp.
_
=
resp
}
}
func (*Client) Rollback
func
(
c
*
Client
)
Rollback
(
ctx
context
.
Context
,
req
*
firestorepb
.
RollbackRequest
,
opts
...
gax
.
CallOption
)
error
Rollback rolls back a transaction.
Example
package
main
import
(
"context"
firestore
"cloud.google.com/go/firestore/apiv1"
firestorepb
"cloud.google.com/go/firestore/apiv1/firestorepb"
)
func
main
()
{
ctx
:=
context
.
Background
()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c
,
err
:=
firestore
.
NewClient
(
ctx
)
if
err
!=
nil
{
// TODO: Handle error.
}
defer
c
.
Close
()
req
:=
& firestorepb
.
RollbackRequest
{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/firestore/apiv1/firestorepb#RollbackRequest.
}
err
=
c
.
Rollback
(
ctx
,
req
)
if
err
!=
nil
{
// TODO: Handle error.
}
}
func (*Client) RunAggregationQuery
func
(
c
*
Client
)
RunAggregationQuery
(
ctx
context
.
Context
,
req
*
firestorepb
.
RunAggregationQueryRequest
,
opts
...
gax
.
CallOption
)
(
firestorepb
.
Firestore_RunAggregationQueryClient
,
error
)
RunAggregationQuery runs an aggregation query.
Rather than producing Document results like Firestore.RunQuery, this API allows running an aggregation to produce a series of AggregationResult server-side.
High-Level Example:
func (*Client) RunQuery
func
(
c
*
Client
)
RunQuery
(
ctx
context
.
Context
,
req
*
firestorepb
.
RunQueryRequest
,
opts
...
gax
.
CallOption
)
(
firestorepb
.
Firestore_RunQueryClient
,
error
)
RunQuery runs a query.
func (*Client) SetGoogleClientInfo
SetGoogleClientInfo sets the name and version of the application in
the x-goog-api-client
header passed on each request. Also passes any
provided key-value pairs. Intended for use by Google-written clients.
Internal use only.
func (*Client) UpdateDocument
func
(
c
*
Client
)
UpdateDocument
(
ctx
context
.
Context
,
req
*
firestorepb
.
UpdateDocumentRequest
,
opts
...
gax
.
CallOption
)
(
*
firestorepb
.
Document
,
error
)
UpdateDocument updates or inserts a document.
Example
package
main
import
(
"context"
firestore
"cloud.google.com/go/firestore/apiv1"
firestorepb
"cloud.google.com/go/firestore/apiv1/firestorepb"
)
func
main
()
{
ctx
:=
context
.
Background
()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c
,
err
:=
firestore
.
NewClient
(
ctx
)
if
err
!=
nil
{
// TODO: Handle error.
}
defer
c
.
Close
()
req
:=
& firestorepb
.
UpdateDocumentRequest
{
// TODO: Fill request struct fields.
// See https://pkg.go.dev/cloud.google.com/go/firestore/apiv1/firestorepb#UpdateDocumentRequest.
}
resp
,
err
:=
c
.
UpdateDocument
(
ctx
,
req
)
if
err
!=
nil
{
// TODO: Handle error.
}
// TODO: Use resp.
_
=
resp
}
func (*Client) Write
func
(
c
*
Client
)
Write
(
ctx
context
.
Context
,
opts
...
gax
.
CallOption
)
(
firestorepb
.
Firestore_WriteClient
,
error
)
Write streams batches of document updates and deletes, in order. This method is only available via gRPC or WebChannel (not REST).
This method is not supported for the REST transport.
Example
package
main
import
(
"context"
"io"
firestore
"cloud.google.com/go/firestore/apiv1"
firestorepb
"cloud.google.com/go/firestore/apiv1/firestorepb"
)
func
main
()
{
ctx
:=
context
.
Background
()
// This snippet has been automatically generated and should be regarded as a code template only.
// It will require modifications to work:
// - It may require correct/in-range values for request initialization.
// - It may require specifying regional endpoints when creating the service client as shown in:
// https://pkg.go.dev/cloud.google.com/go#hdr-Client_Options
c
,
err
:=
firestore
.
NewClient
(
ctx
)
if
err
!=
nil
{
// TODO: Handle error.
}
defer
c
.
Close
()
stream
,
err
:=
c
.
Write
(
ctx
)
if
err
!=
nil
{
// TODO: Handle error.
}
go
func
()
{
reqs
:=
[]
*
firestorepb
.
WriteRequest
{
// TODO: Create requests.
}
for
_
,
req
:=
range
reqs
{
if
err
:=
stream
.
Send
(
req
);
err
!=
nil
{
// TODO: Handle error.
}
}
stream
.
CloseSend
()
}()
for
{
resp
,
err
:=
stream
.
Recv
()
if
err
==
io
.
EOF
{
break
}
if
err
!=
nil
{
// TODO: handle error.
}
// TODO: Use resp.
_
=
resp
}
}
CursorIterator
type
CursorIterator
struct
{
// Response is the raw response for the current page.
// It must be cast to the RPC response type.
// Calling Next() or InternalFetch() updates this value.
Response
interface
{}
// InternalFetch is for use by the Google Cloud Libraries only.
// It is not part of the stable interface of this package.
//
// InternalFetch returns results from a single call to the underlying RPC.
// The number of results is no greater than pageSize.
// If there are no more results, nextPageToken is empty and err is nil.
InternalFetch
func
(
pageSize
int
,
pageToken
string
)
(
results
[]
*
firestorepb
.
Cursor
,
nextPageToken
string
,
err
error
)
// contains filtered or unexported fields
}
CursorIterator manages a stream of *firestorepb.Cursor.
func (*CursorIterator) All
func
(
it
*
CursorIterator
)
All
()
iter
.
Seq2
[
*
firestorepb
.
Cursor
,
error
]
All returns an iterator. If an error is returned by the iterator, the iterator will stop after that iteration.
func (*CursorIterator) Next
func
(
it
*
CursorIterator
)
Next
()
(
*
firestorepb
.
Cursor
,
error
)
Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.
func (*CursorIterator) PageInfo
func
(
it
*
CursorIterator
)
PageInfo
()
*
iterator
.
PageInfo
PageInfo supports pagination. See the [google.golang.org/api/iterator] package for details.
DocumentIterator
type
DocumentIterator
struct
{
// Response is the raw response for the current page.
// It must be cast to the RPC response type.
// Calling Next() or InternalFetch() updates this value.
Response
interface
{}
// InternalFetch is for use by the Google Cloud Libraries only.
// It is not part of the stable interface of this package.
//
// InternalFetch returns results from a single call to the underlying RPC.
// The number of results is no greater than pageSize.
// If there are no more results, nextPageToken is empty and err is nil.
InternalFetch
func
(
pageSize
int
,
pageToken
string
)
(
results
[]
*
firestorepb
.
Document
,
nextPageToken
string
,
err
error
)
// contains filtered or unexported fields
}
DocumentIterator manages a stream of *firestorepb.Document.
func (*DocumentIterator) All
func
(
it
*
DocumentIterator
)
All
()
iter
.
Seq2
[
*
firestorepb
.
Document
,
error
]
All returns an iterator. If an error is returned by the iterator, the iterator will stop after that iteration.
func (*DocumentIterator) Next
func
(
it
*
DocumentIterator
)
Next
()
(
*
firestorepb
.
Document
,
error
)
Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.
func (*DocumentIterator) PageInfo
func
(
it
*
DocumentIterator
)
PageInfo
()
*
iterator
.
PageInfo
PageInfo supports pagination. See the [google.golang.org/api/iterator] package for details.
OperationIterator
type
OperationIterator
struct
{
// Response is the raw response for the current page.
// It must be cast to the RPC response type.
// Calling Next() or InternalFetch() updates this value.
Response
interface
{}
// InternalFetch is for use by the Google Cloud Libraries only.
// It is not part of the stable interface of this package.
//
// InternalFetch returns results from a single call to the underlying RPC.
// The number of results is no greater than pageSize.
// If there are no more results, nextPageToken is empty and err is nil.
InternalFetch
func
(
pageSize
int
,
pageToken
string
)
(
results
[]
*
longrunningpb
.
Operation
,
nextPageToken
string
,
err
error
)
// contains filtered or unexported fields
}
OperationIterator manages a stream of *longrunningpb.Operation.
func (*OperationIterator) All
func
(
it
*
OperationIterator
)
All
()
iter
.
Seq2
[
*
longrunningpb
.
Operation
,
error
]
All returns an iterator. If an error is returned by the iterator, the iterator will stop after that iteration.
func (*OperationIterator) Next
func
(
it
*
OperationIterator
)
Next
()
(
*
longrunningpb
.
Operation
,
error
)
Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.
func (*OperationIterator) PageInfo
func
(
it
*
OperationIterator
)
PageInfo
()
*
iterator
.
PageInfo
PageInfo supports pagination. See the [google.golang.org/api/iterator] package for details.
StringIterator
type
StringIterator
struct
{
// Response is the raw response for the current page.
// It must be cast to the RPC response type.
// Calling Next() or InternalFetch() updates this value.
Response
interface
{}
// InternalFetch is for use by the Google Cloud Libraries only.
// It is not part of the stable interface of this package.
//
// InternalFetch returns results from a single call to the underlying RPC.
// The number of results is no greater than pageSize.
// If there are no more results, nextPageToken is empty and err is nil.
InternalFetch
func
(
pageSize
int
,
pageToken
string
)
(
results
[]
string
,
nextPageToken
string
,
err
error
)
// contains filtered or unexported fields
}
StringIterator manages a stream of string.
func (*StringIterator) All
func
(
it
*
StringIterator
)
All
()
iter
.
Seq2
[
string
,
error
]
All returns an iterator. If an error is returned by the iterator, the iterator will stop after that iteration.
func (*StringIterator) Next
func
(
it
*
StringIterator
)
Next
()
(
string
,
error
)
Next returns the next result. Its second return value is iterator.Done if there are no more results. Once Next returns Done, all subsequent calls will return Done.
func (*StringIterator) PageInfo
func
(
it
*
StringIterator
)
PageInfo
()
*
iterator
.
PageInfo
PageInfo supports pagination. See the [google.golang.org/api/iterator] package for details.