Get started with Cloud Firestore Enterprise edition using server client libraries Stay organized with collections Save and categorize content based on your preferences.
This quickstart shows you how to set upCloud Firestore, add data, then useeither Core operations or Pipeline operations to query the data youjust added in theFirebase console using server client libraries forJava, Node.js, and Python.
Use these client libraries to set up privileged server environments with fullaccess to your database..
Note: Before getting started with these features, make sure you're familiar withthedifferences between Core and Pipeline operations.Create aCloud Firestore database
If you haven't already, create a Firebase project: In theFirebase console, clickAdd project,then follow the on-screen instructions to create a Firebase project or toadd Firebase services to an existingGoogle Cloud project.
Open your project in theFirebase console. In the left panel, expandBuild and then selectFirestore database.
ClickCreate database.
SelectEnterprise for the database mode.
SelectFirestore in Native Mode for the operation mode, which supportsCore and Pipeline operations.
Note: You can create a database in either Native mode or MongoDB compatibilitymode. For more information about MongoDB compatibility mode, see thequickstart for creating MongoDB compatible databases.Select alocation for your database.
Select a starting mode for yourCloud Firestore Security Rules:
- Test mode
Good for getting started with the mobile and web client libraries,but allows anyone to read and overwrite your data. After testing,makesure to review theSecure your data section.
To get started with the web, Apple platforms, or Android SDK, select testmode.
- Production mode
Denies all reads and writes from mobile and web clients.Your authenticated application servers (Node.js, Python, Java) can stillaccess your database.
Your initial set ofCloud Firestore Security Rules will apply to your defaultCloud Firestore database. If you create multiple databases for yourproject, you can deployCloud Firestore Security Rules for each database.
ClickCreate.
(default) database in standard mode with Datastore or Firestore Native APIs can be used withApp Engine.When you enableCloud Firestore, it also enables the API in theCloud API Manager.
Set up your development environment
Add the required dependencies and client libraries to your app.
Node.js
- Add the Firebase Admin SDK to your app:
npminstallfirebase-admin--save
- Follow the instructions below to initializeCloud Firestore with the proper credentials in your environment.
Python
- Add the Firebase Admin SDK to your Python app:
pipinstall--upgradefirebase-admin
- Follow the instructions below to initializeCloud Firestore with the proper credentials in your environment.
Java
- Add the Firebase Admin SDK to your app:
- Using Gradle:
implementation'com.google.firebase:firebase-admin:9.7.1'
- Using Maven:
<dependency><groupId>com.google.firebase</groupId><artifactId>firebase-admin</artifactId><version>9.7.1</version></dependency>
- Using Gradle:
- Follow the instructions below to initializeCloud Firestore with the proper credentials in your environment.
InitializeCloud Firestore
Initialize an instance ofCloud Firestore:
Node.js
TheCloud Firestore SDK is initialized in different ways depending onyour environment. Below are the most common methods. For a complete reference,seeInitializethe Admin SDK.- Initialize onCloud Functions
const{initializeApp,applicationDefault,cert}=require('firebase-admin/app');const{getFirestore,Timestamp,FieldValue,Filter}=require('firebase-admin/firestore');
initializeApp();constdb=getFirestore();
- Initialize onGoogle Cloud
const{initializeApp,applicationDefault,cert}=require('firebase-admin/app');const{getFirestore,Timestamp,FieldValue,Filter}=require('firebase-admin/firestore');
initializeApp({credential:applicationDefault()});constdb=getFirestore();
- Initialize on your own server
To use the Firebase Admin SDK on your own server (or any other Node.js environment),use aservice account.Go toIAM & admin > Service accounts in the Google Cloud console. Generate a new private key and save the JSON file. Then use the file to initialize the SDK:
const{initializeApp,applicationDefault,cert}=require('firebase-admin/app');const{getFirestore,Timestamp,FieldValue,Filter}=require('firebase-admin/firestore');
constserviceAccount=require('./path/to/serviceAccountKey.json');initializeApp({credential:cert(serviceAccount)});constdb=getFirestore();
Python
TheCloud Firestore SDK is initialized in different ways depending onyour environment. Below are the most common methods. For a complete reference,seeInitializethe Admin SDK.importfirebase_adminfromfirebase_adminimportfirestore# Application Default credentials are automatically created.app=firebase_admin.initialize_app()db=firestore.client()
An existing application default credential can also be used to initialize the SDK.
importfirebase_adminfromfirebase_adminimportcredentialsfromfirebase_adminimportfirestore# Use the application default credentials.cred=credentials.ApplicationDefault()firebase_admin.initialize_app(cred)db=firestore.client()
To use the Firebase Admin SDK on your own server, use aservice account.
Go toIAM & admin > Service accounts in the Google Cloud console. Generate a new private key and save the JSON file. Then use the file to initialize the SDK:
importfirebase_adminfromfirebase_adminimportcredentialsfromfirebase_adminimportfirestore# Use a service account.cred=credentials.Certificate('path/to/serviceAccount.json')app=firebase_admin.initialize_app(cred)db=firestore.client()
Java
TheCloud Firestore SDK is initialized in different ways depending onyour environment. Below are the most common methods. For a complete reference,seeInitializethe Admin SDK.importcom.google.auth.oauth2.GoogleCredentials;importcom.google.cloud.firestore.Firestore;importcom.google.firebase.FirebaseApp;importcom.google.firebase.FirebaseOptions;// Use the application default credentialsGoogleCredentialscredentials=GoogleCredentials.getApplicationDefault();FirebaseOptionsoptions=newFirebaseOptions.Builder().setCredentials(credentials).setProjectId(projectId).build();FirebaseApp.initializeApp(options);Firestoredb=FirestoreClient.getFirestore();
To use the Firebase Admin SDK on your own server, use aservice account.
Go toIAM & admin > Service accounts in the Google Cloud console. Generate a new private key and save the JSON file. Then use the file to initialize the SDK:
importcom.google.auth.oauth2.GoogleCredentials;importcom.google.cloud.firestore.Firestore;importcom.google.firebase.FirebaseApp;importcom.google.firebase.FirebaseOptions;// Use a service accountInputStreamserviceAccount=newFileInputStream("path/to/serviceAccount.json");GoogleCredentialscredentials=GoogleCredentials.fromStream(serviceAccount);FirebaseOptionsoptions=newFirebaseOptions.Builder().setCredentials(credentials).build();FirebaseApp.initializeApp(options);Firestoredb=FirestoreClient.getFirestore();
Add data using Core operations
In order to explore Core operations and Pipeline operations for querying data,add data to your database using Core operations.
Cloud Firestore stores data in Documents, which are stored inCollections.Cloud Firestore creates collections and documents implicitlythe first time you add data to the document. You don't need to explicitlycreate collections or documents.
Create a new collection and a document using the following example code.
Node.js
constdocRef=db.collection('users').doc('alovelace');awaitdocRef.set({first:'Ada',last:'Lovelace',born:1815});Java
DocumentReferencedocRef=db.collection("users").document("alovelace");// Add document data with id "alovelace" using a hashmapMap<String,Object>data=newHashMap<>();data.put("first","Ada");data.put("last","Lovelace");data.put("born",1815);//asynchronously write dataApiFuture<WriteResult>result=docRef.set(data);// ...// result.get() blocks on responseSystem.out.println("Update time : "+result.get().getUpdateTime());Python
doc_ref=db.collection("users").document("alovelace")doc_ref.set({"first":"Ada","last":"Lovelace","born":1815})Read data using Core operations
Use the data viewer in theFirebase consoleto quickly verify that you've added data toCloud Firestore.
You can also use the "get" method to retrieve the entire collection.
Node.js
constsnapshot=awaitdb.collection('users').get();snapshot.forEach((doc)=>{console.log(doc.id,'=>',doc.data());});Python
users_ref=db.collection("users")docs=users_ref.stream()fordocindocs:print(f"{doc.id} =>{doc.to_dict()}")
Java
// asynchronously retrieve all usersApiFuture<QuerySnapshot>query=db.collection("users").get();// ...// query.get() blocks on responseQuerySnapshotquerySnapshot=query.get();List<QueryDocumentSnapshot>documents=querySnapshot.getDocuments();for(QueryDocumentSnapshotdocument:documents){System.out.println("User: "+document.getId());System.out.println("First: "+document.getString("first"));if(document.contains("middle")){System.out.println("Middle: "+document.getString("middle"));}System.out.println("Last: "+document.getString("last"));System.out.println("Born: "+document.getLong("born"));}Read data using Pipeline operations
Now you can compare the Pipeline query experience with the Core queryexperience.
Node.js
constreadDataPipeline=db.pipeline().collection("users");// Execute the pipeline and handle the resulttry{constquerySnapshot=awaitreadDataPipeline.execute();querySnapshot.results.forEach((result)=>{console.log(`${result.id} =>${result.data()}`);});}catch(error){console.error("Error getting documents: ",error);}
Python
pipeline=client.pipeline().collection("users")forresultinpipeline.execute():print(f"{result.id} =>{result.data()}")
Java
Pipelinepipeline=firestore.pipeline().collection("users");ApiFuture<Pipeline.Snapshot>future=pipeline.execute();for(com.google.cloud.firestore.PipelineResultresult:future.get().getResults()){System.out.println(result.getId()+" => "+result.getData());}// or, asynchronouslypipeline.execute(newApiStreamObserver<com.google.cloud.firestore.PipelineResult>(){@OverridepublicvoidonNext(com.google.cloud.firestore.PipelineResultresult){System.out.println(result.getId()+" => "+result.getData());}@OverridepublicvoidonError(Throwablet){System.err.println(t);}@OverridepublicvoidonCompleted(){System.out.println("done");}});
Next steps
Deepen your knowledge of Core and Pipeline operations with the following topics:
- Make sure you're familiar with thedifferences between the Core and Pipeline operations
- Learn more about querying withCore operations
- Learn more about querying withPipeline operations.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-18 UTC.