Creating a Firestore client

Creating a Firestore client

Documentation pages that include this code sample

To view the code sample used in context, see the following documentation:

Code sample


import (



func createClient(ctx context.Context) *firestore.Client {
	// Sets your Google Cloud Platform project ID.
	projectID := "YOUR_PROJECT_ID"

	client, err := firestore.NewClient(ctx, projectID)
	if err != nil {
		log.Fatalf("Failed to create client: %v", err)
	// Close client when done with
	// defer client.Close()
	return client


Firestore db = FirestoreOptions.getDefaultInstance().getService();


use Google\Cloud\Firestore\FirestoreClient;

 * Initialize Cloud Firestore with default project ID.
 * ```
 * setup_client_create();
 * ```
function setup_client_create()
    // Create the Cloud Firestore client
    $db = new FirestoreClient();
    printf('Created Cloud Firestore client with default project ID.' . PHP_EOL);


from import firestore

# Project ID is determined by the GCLOUD_PROJECT environment variable
db = firestore.Client()


require "google/cloud/firestore"

firestore = project_id: project_id

puts "Created Cloud Firestore client with given project ID."

What's next

To search and filter code samples for other Google Cloud products, see the Google Cloud sample browser