Create Client with Project ID

Create Client with Project ID

Explore further

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

Code sample


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


use Google\Cloud\Firestore\FirestoreClient;

 * Initialize Cloud Firestore with a provided project ID.
 * @param string $projectId Your Google Cloud Project ID
function setup_client_create_with_project_id(string $projectId): void
    // Create the Cloud Firestore client with a provided project ID.
    $db = new FirestoreClient([
        'projectId' => $projectId,
    printf('Created Cloud Firestore client with project ID: %s' . PHP_EOL, $projectId);


from import firestore

# The `project` parameter is optional and represents which project the client
# will act on behalf of. If not supplied, the client falls back to the default
# project inferred from the environment.
db = firestore.Client(project='my-project-id')

What's next

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