Bu hızlı başlangıç kılavuzunda, Firestore Enterprise sürümünü nasıl ayarlayacağınız, veri ekleyeceğiniz ve ardından Firebase konsoluna eklediğiniz verileri sorgulamak için temel işlemleri veya ardışık düzen işlemlerini nasıl kullanacağınız gösterilmektedir.
Cloud Firestore, mobil veya web SDK'larını ve sunucu istemci kitaplıklarını destekler:
Cloud Firestore; Android, iOS, web ve diğer platformlar için SDK'ları destekler. Cloud Firestore Security Rules ve Firebase Authentication ile birleştirildiğinde mobil ve web SDK'ları, istemcilerin doğrudan Cloud Firestore veritabanınıza bağlandığı sunucusuz uygulama mimarilerini destekler.
Cloud Firestore; Java, Node.js ve Python için sunucu istemci kitaplıklarını destekler. Veritabanınıza tam erişim sağlayan ayrıcalıklı sunucu ortamları oluşturmak için bu istemci kitaplıklarını kullanın. Bu kitaplıklar hakkında daha fazla bilgiyi Sunucu istemci kitaplıkları için hızlı başlangıç bölümünde bulabilirsiniz.
Yapay Zeka Desteği için yapay zeka istemi
Yapay zeka desteği için aşağıdaki istemi yapay zeka kodlama temsilcinize (ör. Android Studio'da Gemini, Antigravity, Claude Code, Codex ve Cursor) kopyalayın. İstemi özelleştirebilir ve temsilcinizle birlikte üzerinde çalışabilirsiniz. Ayrıntılı kurulum bilgileri için Firebase aracı becerileri sayfasını ziyaret edin.
Help me use Firebase in my app.
1. Make sure that **Firebase agent skills** are installed and updated. For Claude Code, Codex, or Cursor agents, help me install the Firebase plugin. For other agents, run `npx skills add firebase/agent-skills`. Always try to use **Firebase agent skills** for Firebase-related tasks.
2. Help me set up and use Firebase for the backend of my app. Set up Firestore database in **Enterprise edition**. Help me to choose the best location for my database instance.
Firestore Enterprise sürümü veritabanı oluşturma
Henüz yapmadıysanız bir Firebase projesi oluşturun: Firebase konsolunda Proje ekle'yi tıklayın, ardından ekrandaki talimatları uygulayarak bir Firebase projesi oluşturun veya mevcut bir Google Cloud projesine Firebase hizmetlerini ekleyin.
Sol panelde Databases & Storage (Veritabanları ve Depolama Alanı) > Firestore'a gidin.
Create database'i (Veritabanı oluştur) tıklayın.
Veritabanı modu için Enterprise'ı seçin.
Çalışma modu için Core ve Pipeline işlemlerini destekleyen Yerel Modda Firestore'u seçin.
Veritabanınız için bir konum seçin.
Cloud Firestore Security Rules cihazınız için bir başlangıç modu seçin:
- Test modu
Mobil ve web istemci kitaplıklarını kullanmaya başlamak için idealdir ancak herkesin verilerinizi okumasına ve üzerine yazmasına izin verir. Testten sonra Verilerinizi güvende tutma bölümünü incelediğinizden emin olun.
Web, Apple platformları veya Android SDK'sını kullanmaya başlamak için test modunu seçin.
- Üretim modu
Mobil ve web istemcilerinden gelen tüm okuma ve yazma işlemlerini reddeder. Kimliği doğrulanmış uygulama sunucularınız (Python) veritabanınıza erişmeye devam edebilir.
İlk Cloud Firestore Security Rules grubunuz varsayılan Cloud Firestore veritabanınıza uygulanır. Projeniz için birden fazla veritabanı oluşturursanız her veritabanı için Cloud Firestore Security Rules dağıtabilirsiniz.
Oluştur'u tıklayın.
Firestore Enterprise sürümünü etkinleştirdiğinizde API, Cloud API Manager'da da etkinleştirilir.
Geliştirme ortamınızı ayarlama
Gerekli bağımlılıkları ve istemci kitaplıklarını uygulamanıza ekleyin.
Web
- Firebase'i web uygulamanıza ekleme talimatlarını uygulayın.
-
Cloud Firestore SDK'sı, npm paketi olarak kullanılabilir.
Hem Firebase'i hem de Cloud Firestore'i içe aktarmanız gerekir.npm install firebase@13.0.0 --save
import { initializeApp } from "firebase/app"; import { getFirestore } from "firebase/firestore";
iOS+
Firebase'i Apple uygulamanıza ekleme talimatlarını uygulayın.
Firebase bağımlılıklarını yüklemek ve yönetmek için Swift Package Manager'ı kullanın.
- Xcode'da uygulama projeniz açıkken File > Swift Packages > Add Package Dependency (Dosya > Swift Paketleri > Paket Bağımlılığı Ekle) bölümüne gidin.
- İstendiğinde Firebase Apple platformları SDK deposunu ekleyin:
- Firestore kitaplığını seçin.
- İşlem tamamlandığında Xcode, arka planda bağımlılıklarınızı otomatik olarak çözmeye ve indirmeye başlar.
https://github.com/firebase/firebase-ios-sdk
Android
- Firebase'i Android uygulamanıza ekleme talimatlarını uygulayın.
- Firebase Android BoM'u kullanarak Android için Cloud Firestore kitaplığına olan bağımlılığı modülünüzün (uygulama düzeyinde) Gradle dosyasında (genellikle
app/build.gradle.ktsveyaapp/build.gradle) tanımlayın.dependencies { // Import the BoM for the Firebase platform implementation(platform("com.google.firebase:firebase-bom:35.0.1")) // Declare the dependency for the Cloud Firestore library // When using the BoM, you don't specify versions in Firebase library dependencies implementation("com.google.firebase:firebase-firestore") }
Firebase Android BoM'u kullandığınızda uygulamanız her zaman Firebase Android kitaplıklarının uyumlu sürümlerini kullanır.
(Alternatif) BoM kullanmadan Firebase kitaplığı bağımlılıklarını bildirin.
Firebase BoM kullanmamayı tercih ederseniz her Firebase kitaplığı sürümünü kendi bağımlılık satırında belirtmeniz gerekir.
Uygulamanızda birden fazla Firebase kitaplığı kullanıyorsanız kitaplık sürümlerini yönetmek için BoM kullanmanızı önemle tavsiye ederiz. Bu sayede tüm sürümlerin uyumlu olmasını sağlayabilirsiniz.
dependencies { // Declare the dependency for the Cloud Firestore library // When NOT using the BoM, you must specify versions in Firebase library dependencies implementation("com.google.firebase:firebase-firestore:27.0.0") }
Kotlin'e özel bir kitaplık modülü mü arıyorsunuz? Ekim 2023 sürümünden itibaren hem Kotlin hem de Java geliştiricileri ana kitaplık modülüne bağlı olabilir (ayrıntılar için bu girişimle ilgili SSS bölümüne bakın).
Cloud Firestore başlatılıyor
Cloud Firestore örneğini başlatın:
Web
import { initializeApp } from "firebase/app"; import { getFirestore } from "firebase/firestore"; // TODO: Replace the following with your app's Firebase project configuration // See: https://support.google.com/firebase/answer/7015592 const firebaseConfig = { FIREBASE_CONFIGURATION }; // Initialize Firebase const app = initializeApp(firebaseConfig); // When initializing Firestore, remember to use the name of the database you created earlier: const db = initializeFirestore(app, {}, 'your-new-enterprise-database');
FIREBASE_CONFIGURATION yerine web uygulamanızın firebaseConfig değerini girin.
Cihazın bağlantısı kesildiğinde verileri korumak için Çevrimdışı Verileri Etkinleştirme belgelerine bakın.
Swift
import FirebaseCore import FirebaseFirestore FirebaseApp.configure() // When initializing Firestore, remember to use the name of the database you created earlier: let db = Firestore.firestore(database: "your-new-enterprise-database")
Kotlin
// Access a Cloud Firestore instance from your Activity // When initializing Firestore, remember to use the name of the database you created earlier: val firestore = FirebaseFirestore.getInstance("your-new-enterprise-database")
Java
// Access a Cloud Firestore instance from your Activity // When initializing Firestore, remember to use the name of the database you created earlier: FirebaseFirestore firestore = FirebaseFirestore.getInstance("your-new-enterprise-database");
Temel işlemleri kullanarak veri ekleme
Veri sorgulamak için temel işlemleri ve ardışık düzen işlemlerini keşfetmek üzere temel işlemleri kullanarak veritabanınıza veri ekleyin.
Cloud Firestore, verileri koleksiyonlarda depolanan dokümanlarda depolar. Cloud Firestore, dokümana ilk kez veri eklediğinizde koleksiyonları ve dokümanları dolaylı olarak oluşturur. Koleksiyonları veya dokümanları açıkça oluşturmanız gerekmez.
Aşağıdaki örnek kodu kullanarak yeni bir koleksiyon ve doküman oluşturun.
Web
import { collection, addDoc } from "firebase/firestore"; try { const docRef = await addDoc(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
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 ID do { let ref = try await db.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 name val user = hashMapOf( "first" to "Ada", "last" to "Lovelace", "born" to 1815, ) // Add a new document with a generated ID db.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 name Map<String, Object> user = new HashMap<>(); user.put("first", "Ada"); user.put("last", "Lovelace"); user.put("born", 1815); // Add a new document with a generated ID db.collection("users") .add(user) .addOnSuccessListener(new OnSuccessListener<DocumentReference>() { @Override public void onSuccess(DocumentReference documentReference) { Log.d(TAG, "DocumentSnapshot added with ID: " + documentReference.getId()); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Log.w(TAG, "Error adding document", e); } });
Şimdi users koleksiyonuna başka bir belge ekleyin. Bu belgede, ilk belgede görünmeyen bir anahtar/değer çifti (ikinci ad) bulunduğuna dikkat edin. Bir koleksiyondaki belgeler farklı bilgi kümeleri içerebilir.
Web
// Add a second document with a generated ID. import { addDoc, collection } from "firebase/firestore"; try { const docRef = await addDoc(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
// 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 { let ref = try await db.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 name val user = hashMapOf( "first" to "Alan", "middle" to "Mathison", "last" to "Turing", "born" to 1912, ) // Add a new document with a generated ID db.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 name Map<String, Object> user = new HashMap<>(); user.put("first", "Alan"); user.put("middle", "Mathison"); user.put("last", "Turing"); user.put("born", 1912); // Add a new document with a generated ID db.collection("users") .add(user) .addOnSuccessListener(new OnSuccessListener<DocumentReference>() { @Override public void onSuccess(DocumentReference documentReference) { Log.d(TAG, "DocumentSnapshot added with ID: " + documentReference.getId()); } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { Log.w(TAG, "Error adding document", e); } });
Temel işlemleri kullanarak verileri okuma
Cloud Firestore'ye veri eklediğinizi hızlıca doğrulamak için Firebase konsolundaki veri görüntüleyiciyi kullanın.
Koleksiyonun tamamını almak için "get" yöntemini de kullanabilirsiniz.
Web
import { collection, getDocs } from "firebase/firestore"; const querySnapshot = await getDocs(collection(db, "users")); querySnapshot.forEach((doc) => { console.log(doc.id, "=>", doc.data()); });
Web
db.collection("users").get().then((querySnapshot) => { querySnapshot.forEach((doc) => { console.log(doc.id, "=>", doc.data()); }); });
Swift
do { let snapshot = try await db.collection("users").getDocuments() for document in snapshot.documents { print("\(document.documentID) => \(document.data())") } } catch { print("Error getting documents: \(error)") }
Kotlin
db.collection("users") .get() .addOnSuccessListener { result -> for (document in result) { Log.d(TAG, "${document.id} => ${document.data}") } } .addOnFailureListener { exception -> Log.w(TAG, "Error getting documents.", exception) }
Java
db.collection("users") .get() .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() { @Override public void onComplete(@NonNull Task<QuerySnapshot> task) { if (task.isSuccessful()) { for (QueryDocumentSnapshot document : task.getResult()) { Log.d(TAG, document.getId() + " => " + document.getData()); } } else { Log.w(TAG, "Error getting documents.", task.getException()); } } });
Pipeline işlemlerini kullanarak verileri okuma
Artık Pipeline sorgu deneyimini Core sorgu deneyimiyle karşılaştırabilirsiniz.
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"; const readDataPipeline = db.pipeline() .collection("users"); // Execute the pipeline and handle the result try { const querySnapshot = await execute(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. let snapshot = try await db.pipeline() .collection("users") .execute() // Execute the pipeline to retrieve documents. // Iterate through the documents in the pipeline results, similar to a regular query // snapshot. for result in snapshot.results { print("\(result.id ?? "no ID") => \(result.data)") } } catch { print("Error getting documents with pipeline: \(error)") }
Kotlin
val readDataPipeline = db.pipeline() .collection("users") // Execute the pipeline and handle the result readDataPipeline.execute() .addOnSuccessListener { result -> for (document in result) { println("${document.getId()} => ${document.getData()}") } } .addOnFailureListener { exception -> println("Error getting documents: $exception") }
Java
Pipeline readDataPipeline = db.pipeline() .collection("users"); readDataPipeline.execute() .addOnSuccessListener(new OnSuccessListener<Pipeline.Snapshot>() { @Override public void onSuccess(Pipeline.Snapshot snapshot) { for (PipelineResult result : snapshot.getResults()) { System.out.println(result.getId() + " => " + result.getData()); } } }) .addOnFailureListener(new OnFailureListener() { @Override public void onFailure(@NonNull Exception e) { System.out.println("Error getting documents: " + e); } });
Mobil ve web SDK'ları için verilerinizin güvenliğini sağlama
Web, Android veya Apple platformları SDK'sını kullanıyorsanız Cloud Firestore'teki verilerinizin güvenliğini sağlamak için Firebase Authentication ve Cloud Firestore Security Rules'ı kullanın.
Başlangıç için kullanabileceğiniz bazı temel kural kümeleri aşağıda verilmiştir. Güvenlik kurallarınızı Firebase konsolunda Databases & Storage (Veritabanları ve Depolama Alanı) > Firestore > Rules (Kurallar) sekmesinden değiştirebilirsiniz.
Kimlik doğrulama gerekli
// Allow read/write access to a document keyed by the user's UID
service cloud.firestore {
match /databases/{database}/documents {
match /users/{uid} {
allow read, write: if request.auth != null && request.auth.uid == uid;
}
}
}
Üretim modu
// Deny read/write access to all users under any conditions
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if false;
}
}
}
Web, Android veya iOS uygulamanızı üretim ortamına dağıtmadan önce, yalnızca uygulama istemcilerinizin Cloud Firestore verilerinize erişebildiğinden emin olmak için gerekli adımları uygulayın. Uygulama Kontrolü belgelerine bakın.
Sunucu SDK'larından birini kullanıyorsanız Cloud Firestore uygulamasındaki verilerinizin güvenliğini sağlamak için Identity and Access Management (IAM) kullanın.
Sonraki adımlar
Aşağıdaki konularla Core ve Pipeline işlemleri hakkındaki bilgilerinizi derinleştirin:
- Temel işlemler ile sorgulama hakkında daha fazla bilgi edinin.
- Ardışık düzen işlemleri ile sorgulama hakkında daha fazla bilgi edinin.
- Görevleri daha etkili bir şekilde yürütmek için yapay zeka geliştirme araçlarınızı nasıl geliştireceğinizi ve Firebase aracı becerileri ile Cloud Firestore en iyi uygulamalarını (ör. Cloud Firestore Security Rules yazma) nasıl kullanacağınızı öğrenin.