Get started with Cloud Firestore Enterprise edition Stay organized with collections Save and categorize content based on your preferences.
This quickstart shows you how to set up Cloud Firestore Enterprise edition, add data, thenuse either Core operations or Pipeline operations to query the data youjust added in theFirebase console.
Cloud Firestore supports mobile or web SDKs and server client libraries:
Cloud Firestore supportsSDKs for Android, iOS, and web and more. Combined withCloud Firestore Security Rules andFirebase Authentication, the mobile and web SDKs supportserverless app architectures where clients connect directly to yourCloud Firestore database.
Cloud Firestore supportsserver client libraries for Java, Node.js, andPython. Use these client libraries to set up privileged serverenvironments with full access to your database. Learn more about these librariesin theQuickstart for server client libraries.
Create a Cloud Firestore Enterprise edition 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 (Python) can still access yourdatabase.
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 enable Cloud Firestore Enterprise edition, it also enables the API in theCloud API Manager.
Set up your development environment
Add the required dependencies and client libraries to your app.
Web
- Follow the instructions toadd Firebase to your web app.
- TheCloud Firestore SDK is available as an npm package.
You'll need to import both Firebase andCloud Firestore.npminstallfirebase@12.9.0--save
import{initializeApp}from"firebase/app";import{getFirestore}from"firebase/firestore";
iOS+
Follow the instructions toadd Firebase to your Apple app.
Use Swift Package Manager to install and manage Firebase dependencies.
Visitour installation guide to learn about the different ways you can add Firebase SDKs to your Apple project, including importing frameworks directly and using CocoaPods.- In Xcode, with your app project open, navigate toFile > Swift Packages > Add Package Dependency.
- When prompted, add the Firebase Apple platforms SDK repository:
- Choose the Firestore library.
- When finished, Xcode will automatically begin resolving and downloading your dependencies in the background.
https://github.com/firebase/firebase-ios-sdk
Android
- Follow the instructions toadd Firebase to your Android app.
- Using theFirebase Android BoM, declare the dependency for theCloud Firestore library for Android in yourmodule (app-level) Gradle file (usually
app/build.gradle.ktsorapp/build.gradle).dependencies{// Import the BoM for the Firebase platformimplementation(platform("com.google.firebase:firebase-bom:34.9.0"))// Declare the dependency for theCloud Firestore library// When using the BoM, you don't specify versions in Firebase library dependenciesimplementation("com.google.firebase:firebase-firestore")}
By using theFirebase Android BoM, your app will always use compatible versions of the Firebase Android libraries.
(Alternative) Declare Firebase library dependencieswithout using theBoM
If you choose not to use theFirebase BoM, you must specify each Firebase library version in its dependency line.
Note that if you usemultiple Firebase libraries in your app, we highly recommend using theBoM to manage library versions, which ensures that all versions are compatible.
dependencies{// Declare the dependency for theCloud Firestore library// When NOT using the BoM, you must specify versions in Firebase library dependenciesimplementation("com.google.firebase:firebase-firestore:26.1.0")}
Looking for a Kotlin-specific library module? Starting with theOctober 2023 release, both Kotlin and Java developers can depend on the main library module (for details, see theFAQ about this initiative).
InitializeCloud Firestore
Initialize an instance ofCloud Firestore:
Web
import{initializeApp}from"firebase/app";import{getFirestore}from"firebase/firestore";//TODO:Replacethefollowingwithyourapp's Firebase project configuration//See:https://support.google.com/firebase/answer/7015592constfirebaseConfig={FIREBASE_CONFIGURATION};//InitializeFirebaseconstapp=initializeApp(firebaseConfig);//WheninitializingFirestore,remembertousethenameofthedatabaseyoucreatedearlier:constdb=initializeFirestore(app,{},'your-new-enterprise-database');
ReplaceFIREBASE_CONFIGURATION with your web app'sfirebaseConfig.
To persist data when the device loses its connection, see theEnable Offline Data documentation.
Swift
importFirebaseCoreimportFirebaseFirestoreFirebaseApp.configure()//WheninitializingFirestore,remembertousethenameofthedatabaseyoucreatedearlier:letdb=Firestore.firestore(database:"your-new-enterprise-database")
Kotlin
// Access aCloud Firestore instance from your Activity// When initializing Firestore, remember to use the name of the database you created earlier:valfirestore=FirebaseFirestore.getInstance("your-new-enterprise-database")
Java
// Access aCloud Firestore instance from your Activity// When initializing Firestore, remember to use the name of the database you created earlier:FirebaseFirestorefirestore=FirebaseFirestore.getInstance("your-new-enterprise-database");
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.
Web
import{collection,addDoc}from"firebase/firestore";try{constdocRef=awaitaddDoc(collection(db,"users"),{first:"Ada",last:"Lovelace",born:1815});console.log("Document written with ID: ",docRef.id);}catch(e){console.error("Error adding document: ",e);}
Web
Learn more about the tree-shakeable modular Web API and its advantages over the namespaced API.db.collection("users").add({first:"Ada",last:"Lovelace",born:1815}).then((docRef)=>{console.log("Document written with ID: ",docRef.id);}).catch((error)=>{console.error("Error adding document: ",error);});
Swift
// Add a new document with a generated IDdo{letref=tryawaitdb.collection("users").addDocument(data:["first":"Ada","last":"Lovelace","born":1815])print("Document added with ID:\(ref.documentID)")}catch{print("Error adding document:\(error)")}
Kotlin
// Create a new user with a first and last namevaluser=hashMapOf("first"to"Ada","last"to"Lovelace","born"to1815,)// Add a new document with a generated IDdb.collection("users").add(user).addOnSuccessListener{documentReference->Log.d(TAG,"DocumentSnapshot added with ID:${documentReference.id}")}.addOnFailureListener{e->Log.w(TAG,"Error adding document",e)}
Java
// Create a new user with a first and last nameMap<String,Object>user=newHashMap<>();user.put("first","Ada");user.put("last","Lovelace");user.put("born",1815);// Add a new document with a generated IDdb.collection("users").add(user).addOnSuccessListener(newOnSuccessListener<DocumentReference>(){@OverridepublicvoidonSuccess(DocumentReferencedocumentReference){Log.d(TAG,"DocumentSnapshot added with ID: "+documentReference.getId());}}).addOnFailureListener(newOnFailureListener(){@OverridepublicvoidonFailure(@NonNullExceptione){Log.w(TAG,"Error adding document",e);}});
Now add another document to theusers collection. Notice that this documentincludes a key-value pair (middle name) that does not appear in the firstdocument. Documents in a collection can contain different sets of information.
Web
// Add a second document with a generated ID.import{addDoc,collection}from"firebase/firestore";try{constdocRef=awaitaddDoc(collection(db,"users"),{first:"Alan",middle:"Mathison",last:"Turing",born:1912});console.log("Document written with ID: ",docRef.id);}catch(e){console.error("Error adding document: ",e);}
Web
Learn more about the tree-shakeable modular Web API and its advantages over the namespaced API.// Add a second document with a generated ID.db.collection("users").add({first:"Alan",middle:"Mathison",last:"Turing",born:1912}).then((docRef)=>{console.log("Document written with ID: ",docRef.id);}).catch((error)=>{console.error("Error adding document: ",error);});
Swift
// Add a second document with a generated ID.do{letref=tryawaitdb.collection("users").addDocument(data:["first":"Alan","middle":"Mathison","last":"Turing","born":1912])print("Document added with ID:\(ref.documentID)")}catch{print("Error adding document:\(error)")}
Kotlin
// Create a new user with a first, middle, and last namevaluser=hashMapOf("first"to"Alan","middle"to"Mathison","last"to"Turing","born"to1912,)// Add a new document with a generated IDdb.collection("users").add(user).addOnSuccessListener{documentReference->Log.d(TAG,"DocumentSnapshot added with ID:${documentReference.id}")}.addOnFailureListener{e->Log.w(TAG,"Error adding document",e)}
Java
// Create a new user with a first, middle, and last nameMap<String,Object>user=newHashMap<>();user.put("first","Alan");user.put("middle","Mathison");user.put("last","Turing");user.put("born",1912);// Add a new document with a generated IDdb.collection("users").add(user).addOnSuccessListener(newOnSuccessListener<DocumentReference>(){@OverridepublicvoidonSuccess(DocumentReferencedocumentReference){Log.d(TAG,"DocumentSnapshot added with ID: "+documentReference.getId());}}).addOnFailureListener(newOnFailureListener(){@OverridepublicvoidonFailure(@NonNullExceptione){Log.w(TAG,"Error adding document",e);}});
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.
Web
import{collection,getDocs}from"firebase/firestore";constquerySnapshot=awaitgetDocs(collection(db,"users"));querySnapshot.forEach((doc)=>{console.log(`${doc.id} =>${doc.data()}`);});
Web
Learn more about the tree-shakeable modular Web API and its advantages over the namespaced API.db.collection("users").get().then((querySnapshot)=>{querySnapshot.forEach((doc)=>{console.log(`${doc.id} =>${doc.data()}`);});});
Swift
do{letsnapshot=tryawaitdb.collection("users").getDocuments()fordocumentinsnapshot.documents{print("\(document.documentID) =>\(document.data())")}}catch{print("Error getting documents:\(error)")}
Kotlin
db.collection("users").get().addOnSuccessListener{result->for(documentinresult){Log.d(TAG,"${document.id} =>${document.data}")}}.addOnFailureListener{exception->Log.w(TAG,"Error getting documents.",exception)}
Java
db.collection("users").get().addOnCompleteListener(newOnCompleteListener<QuerySnapshot>(){@OverridepublicvoidonComplete(@NonNullTask<QuerySnapshot>task){if(task.isSuccessful()){for(QueryDocumentSnapshotdocument:task.getResult()){Log.d(TAG,document.getId()+" => "+document.getData());}}else{Log.w(TAG,"Error getting documents.",task.getException());}}});
Read data using Pipeline operations
Now you can compare the Pipeline query experience with the Core queryexperience.
Web
// The import/require of "firebase/firestore/pipelines" has a side-effect// of extending the Firestore class with the `.pipeline()` method.// Without this import/require, you will not be able to create a Pipeline.// import { execute } from "firebase/firestore/pipelines";constreadDataPipeline=db.pipeline().collection("users");// Execute the pipeline and handle the resulttry{constquerySnapshot=awaitexecute(readDataPipeline);querySnapshot.results.forEach((result)=>{console.log(`${result.id} =>${result.data()}`);});}catch(error){console.error("Error getting documents: ",error);}
Swift
do{// Initialize a Firestore Pipeline instance and specify the "users" collection as the// input stage.letsnapshot=tryawaitdb.pipeline().collection("users").execute()// Execute the pipeline to retrieve documents.// Iterate through the documents in the pipeline results, similar to a regular query// snapshot.forresultinsnapshot.results{print("\(result.id??"no ID") =>\(result.data)")}}catch{print("Error getting documents with pipeline:\(error)")}
Kotlin
valreadDataPipeline=db.pipeline().collection("users")// Execute the pipeline and handle the resultreadDataPipeline.execute().addOnSuccessListener{result->for(documentinresult){println("${document.getId()} =>${document.getData()}")}}.addOnFailureListener{exception->println("Error getting documents:$exception")}
Java
PipelinereadDataPipeline=db.pipeline().collection("users");readDataPipeline.execute().addOnSuccessListener(newOnSuccessListener<Pipeline.Snapshot>(){@OverridepublicvoidonSuccess(Pipeline.Snapshotsnapshot){for(PipelineResultresult:snapshot.getResults()){System.out.println(result.getId()+" => "+result.getData());}}}).addOnFailureListener(newOnFailureListener(){@OverridepublicvoidonFailure(@NonNullExceptione){System.out.println("Error getting documents: "+e);}});
Secure your data for mobile and web SDKs
If you're using the web, Android, or Apple platforms SDK, useFirebaseAuthentication andCloud Firestore Security Rules to secure your data inCloud Firestore.
Here are some basic rule sets you can use to get started. You can modify yoursecurity rules in theRulestab ofthe console.
Auth required
// Allow read/write access to a document keyed by the user's UIDservicecloud.firestore{match/databases/{database}/documents{match/users/{uid}{allowread,write:ifrequest.auth!=null &&request.auth.uid==uid;}}}Production mode
// Deny read/write access to all users under any conditionsservicecloud.firestore{match/databases/{database}/documents{match/{document=**}{allowread,write:iffalse;}}}Before you deploy your web, Android, or iOS app to production, also take stepsto ensure that only your app clients can access yourCloud Firestore data.See theApp Check documentation.
If you're using one of the server SDKs, useIdentity and Access Management(IAM) to secure your datainCloud Firestore.
Next steps
Deepen your knowledge of Core and Pipeline operations with the following topics:
- 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.