Create a Firestore document reference from a document path

Create a Firestore document reference from a document path

Explore further

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

Code sample

C#

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

DocumentReference documentRef = db.Document("users/alovelace");

Go

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 createDocReferenceFromString(client *firestore.Client) {
	// Reference to a document with id "alovelace" in the collection "users"
	alovelaceRef := client.Doc("users/alovelace")

	_ = alovelaceRef
}

Java

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

// Reference to a document with id "alovelace" in the collection "users"
DocumentReference document = db.document("users/alovelace");

Node.js

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

const alovelaceDocumentRef = db.doc('users/alovelace');

PHP

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

$document = $db->document('users/alovelace');

Python

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

a_lovelace_ref = db.document("users/alovelace")

Ruby

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

document_path_ref = firestore.doc "users/alovelace"

What's next

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