Create a Firestore collection reference

Create a Firestore collection reference

Explore further

For detailed documentation that includes this code sample, see the following:

Code sample

To authenticate to Firestore, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

CollectionReference collectionRef = db.Collection("users");

To authenticate to Firestore, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.


import (
	"cloud.google.com/go/firestore"
)

func createCollectionReference(client *firestore.Client) {
	usersRef := client.Collection("users")

	_ = usersRef
}

To authenticate to Firestore, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

// Reference to the collection "users"
CollectionReference collection = db.collection("users");

To authenticate to Firestore, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

const usersCollectionRef = db.collection('users');

To authenticate to Firestore, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

$collection = $db->collection('samples/php/users');

To authenticate to Firestore, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

users_ref = db.collection("users")

To authenticate to Firestore, set up Application Default Credentials. For more information, see Set up authentication for a local development environment.

collection_ref = firestore.col "users"

What's next

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