Firestore Enterprise সংস্করণ ব্যবহার শুরু করা

এই কুইকস্টার্ট আপনাকে দেখায় যে কীভাবে Firestore Enterprise সংস্করণ সেট আপ করতে হয়, ডেটা যোগ করতে হয়, তারপর আপনি যে ডেটা যোগ করেছেন তা জিজ্ঞাসা করতে কোর অপারেশন বা পাইপলাইন অপারেশন ব্যবহার করুন শুধু Firebase কনসোলে যোগ করা হয়েছে।

Cloud Firestore মোবাইল বা ওয়েব SDK এবং সার্ভার ক্লায়েন্ট লাইব্রেরিতে কাজ করে:

  • Cloud Firestore Android, iOS, ওয়েব ও আরও অনেক কিছুর জন্য SDK সাপোর্ট করে। Cloud Firestore Security Rules এবং Firebase Authentication-এর সাথে যুক্ত হয়ে, মোবাইল এবং ওয়েব SDK, সার্ভারলেস অ্যাপ আর্কিটেকচারকে সাপোর্ট করে যেখানে ক্লায়েন্ট সরাসরি আপনার Cloud Firestore ডেটাবেসের সাথে কানেক্ট করে।

  • Cloud Firestore-এ Java, Node.js ও Python-এর জন্য সার্ভার ক্লায়েন্ট লাইব্রেরি কাজ করে। আপনার ডেটাবেসে সম্পূর্ণ অ্যাক্সেস সহ বিশেষাধিকারপ্রাপ্ত সার্ভার এনভায়রনমেন্ট সেট-আপ করতে এইসব ক্লায়েন্ট লাইব্রেরি ব্যবহার করুন। সার্ভার ক্লায়েন্ট লাইব্রেরির জন্য ক্যুইকস্টার্ট-এ এইসব লাইব্রেরি সম্পর্কে আরও জানুন।

AI-এর মাধ্যমে সহায়তা পেতে, নিচের প্রম্পটটি আপনার AI কোডিং এজেন্টে (যেমন, Android Studio-তে Gemini, Antigravity, Claude Code, Codex এবং Cursor) কপি করুন। আপনি প্রম্পট কাস্টমাইজ করতে এবং আপনার এজেন্টের সাথে আইটারেট করতে পারবেন। ইনস্টলেশন সংক্রান্ত বিস্তারিত তথ্যের জন্য Firebase এজেন্ট সংক্রান্ত দক্ষতা দেখুন।

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 এডিশন ডেটাবেস তৈরি করা

  1. আপনি আগে থেকে Firebase প্রোজেক্ট তৈরি না করে থাকলে, তা করুন: Firebase কনসোল থেকে প্রোজেক্ট যোগ করুন বিকল্পে ক্লিক করুন, তারপর Firebase প্রোজেক্ট তৈরি করতে অথবা আগে থেকে থাকা Google Cloud প্রোজেক্টে Firebase পরিষেবা যোগ করতে অন-স্ক্রিন নির্দেশাবলী অনুসরণ করুন।

  2. বাঁদিকের প্যানেলে, ডেটাবেস ও স্টোরেজ > Firestore বিকল্পে যান।

  3. ডেটাবেস তৈরি করুন বিকল্পে ক্লিক করুন।

  4. ডেটাবেস মোডের জন্য Enterprise বেছে নিন।

  5. অপারেশন মোডের জন্য নেটিভ মোডে Firestore বেছে নিন, যা কোর এবং পাইপলাইন অপারেশনকে সাপোর্ট করে।

  6. আপনার ডেটাবেসের জন্য একটি লোকেশন বেছে নিন।

  7. আপনার Cloud Firestore Security Rules-এর জন্য একটি স্টার্টিং মোড বেছে নিন:

    টেস্ট মোড

    মোবাইল ও ওয়েব ক্লায়েন্ট লাইব্রেরি ব্যবহার শুরু করার জন্য ভাল, তবে এটি যে কাউকে আপনার ডেটা পড়তে ও ওভাররাইট করতে দেয়। টেস্ট করার পরে, আপনার ডেটা সুরক্ষিত করুন বিভাগটি পর্যালোচনা করতে ভুলবেন না।

    ওয়েব, Apple প্ল্যাটফর্ম বা Android SDK-এর মাধ্যমে শুরু করতে, টেস্ট মোড বেছে নিন।

    প্রোডাকশন মোড

    মোবাইল ও ওয়েব ক্লায়েন্ট থেকে সব রিড ও রাইট অ্যাক্সেস বাতিল করে। আপনার যাচাই করা অ্যাপ্লিকেশন সার্ভার (Python) এখনও আপনার ডেটাবেস অ্যাক্সেস করতে পারবে।

    আপনার Cloud Firestore Security Rules-এর প্রাথমিক সেট আপনার ডিফল্ট Cloud Firestore ডেটাবেসে প্রযোজ্য হবে। আপনার প্রোজেক্টের জন্য একাধিক ডেটাবেস তৈরি করলে, প্রতিটি ডেটাবেসের জন্য Cloud Firestore Security Rules ডিপ্লয় করতে পারবেন।

  8. তৈরি করুন বিকল্পে ক্লিক করুন।

আপনি Firestore Enterprise সংস্করণ চালু করলে, এটি Cloud API Manager-এ API-ও চালু করে।

আপনার ডেভেলপমেন্ট এনভায়রনমেন্ট সেট-আপ করুন

আপনার অ্যাপে প্রয়োজনীয় ডিপেন্ডেন্সি ও ক্লায়েন্ট লাইব্রেরি যোগ করুন।

Web

  1. আপনার ওয়েব অ্যাপে Firebase যোগ করতে নির্দেশাবলী অনুসরণ করুন।
  2. Cloud Firestore SDK, npm প্যাকেজ হিসেবে উপলভ্য।
    npm install firebase@13.0.0 --save
    আপনাকে Firebase ও Cloud Firestore, দুটিই ইম্পোর্ট করতে হবে।
    import { initializeApp } from "firebase/app";
    import { getFirestore } from "firebase/firestore";
iOS+

আপনার Apple অ্যাপে Firebase যোগ করতে নির্দেশাবলী অনুসরণ করুন।

Firebase ডিপেন্ডেন্সি ইনস্টল ও ম্যানেজ করতে Swift প্যাকেজ ম্যানেজার ব্যবহার করুন।

  1. Xcode-এ, আপনার অ্যাপ প্রোজেক্ট খোলা রেখে, ফাইল > Swift প্যাকেজ > প্যাকেজ ডিপেন্ডেন্সি যোগ করুন বিকল্পে নেভিগেট করুন।
  2. প্রম্পট করা হলে, Firebase Apple প্ল্যাটফর্ম SDK রিপোজিটরি যোগ করুন:
  3.   https://github.com/firebase/firebase-ios-sdk
      
  4. Firestore লাইব্রেরি বেছে নিন।
  5. হয়ে গেলে, Xcode অটোমেটিক ব্যাকগ্রাউন্ডে আপনার ডিপেন্ডেন্সি সমাধান ও ডাউনলোড করা শুরু করবে।
Android
  1. আপনার Android অ্যাপে Firebase যোগ করতে নির্দেশাবলী অনুসরণ করুন।
  2. Firebase Android BoM ব্যবহার করে, আপনার মডিউল (অ্যাপ-লেভেল) Gradle ফাইলে (সাধারণত app/build.gradle.kts বা app/build.gradle) Android-এর জন্য Cloud Firestore লাইব্রেরির ডিপেন্ডেন্সি ঘোষণা করুন।
    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 ব্যবহার করে, আপনার অ্যাপ সবসময় Firebase Android লাইব্রেরির মানানসই ভার্সন ব্যবহার করবে।

    (বিকল্প) BoM ব্যবহার না করে Firebase লাইব্রেরি ডিপেন্ডেন্সি ঘোষণা করুন

    আপনি Firebase BoM ব্যবহার না করার সিদ্ধান্ত নিলে, আপনাকে অবশ্যই প্রতিটি Firebase লাইব্রেরি ভার্সন এর ডিপেন্ডেন্সি লাইনে উল্লেখ করতে হবে।

    মনে রাখবেন, আপনার অ্যাপে একাধিক Firebase লাইব্রেরি ব্যবহার করলে, লাইব্রেরি ভার্সন ম্যানেজ করার জন্য আমরা BoM ব্যবহার করার জন্য বিশেষভাবে সাজেস্ট করি, যা সব ভার্সন মানানসই কিনা তা নিশ্চিত করে।

    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-নির্দিষ্ট লাইব্রেরি মডিউল খুঁজছেন? অক্টোবর ২০২৩ রিলিজ থেকে শুরু করে, Kotlin ও Java ডেভেলপাররা প্রধান লাইব্রেরি মডিউলের উপর নির্ভর করতে পারবেন (বিস্তারিত জানতে, এই উদ্যোগ সম্পর্কে প্রায়শই জিজ্ঞাসিত প্রশ্ন দেখুন)।

Cloud Firestore শুরু করুন

Cloud Firestore-এর ইনস্ট্যান্স শুরু করুন:

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-এর জায়গায় আপনার ওয়েব অ্যাপের firebaseConfig লিখুন।

ডিভাইসের কানেকশন চলে গেলে ডেটা সেভ করে রাখতে, অফলাইন ডেটা চালু করুন ডকুমেন্টেশন দেখুন।

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");

Core অপারেশন ব্যবহার করে ডেটা যোগ করুন

ডেটা কোয়েরি করার জন্য Core অপারেশন ও Pipeline অপারেশন এক্সপ্লোর করতে, Core অপারেশন ব্যবহার করে আপনার ডেটাবেসে ডেটা যোগ করুন।

Cloud Firestore ডকুমেন্টে ডেটা স্টোর করে, যা কালেকশনে স্টোর করা হয়। আপনি প্রথমবার ডকুমেন্টে ডেটা যোগ করলে, Cloud Firestore অন্তর্নিহিতভাবে কালেকশন ও ডকুমেন্ট তৈরি করে। আপনাকে আলাদা করে কালেকশন বা ডকুমেন্ট তৈরি করতে হবে না।

নিম্নলিখিত উদাহরণ কোড ব্যবহার করে একটি নতুন সংগ্রহ এবং একটি ডকুমেন্ট তৈরি করুন।

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
মনে রাখবেন: এই প্রোডাক্ট watchOS এবং অ্যাপ ক্লিপ টার্গেটে উপলভ্য নয়।
// 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);
            }
        });

এখন users কালেকশনে অন্য একটি ডকুমেন্ট যোগ করুন। লক্ষ্য করুন যে এই ডকুমেন্টে একটি কী-ভ্যালু পেয়ার (নামের মধ্যাংশ) আছে যা প্রথম ডকুমেন্টে নেই। কালেকশনের মধ্যে থাকা ডকুমেন্টে বিভিন্ন ধরনের তথ্য থাকতে পারে।

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
মনে রাখবেন: এই প্রোডাক্ট watchOS এবং অ্যাপ ক্লিপ টার্গেটে উপলভ্য নয়।
// 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);
            }
        });

Core অপারেশন ব্যবহার করে ডেটা পড়া

Cloud Firestore-এ ডেটা যোগ করেছেন কিনা তা দ্রুত যাচাই করতে Firebase কনসোলে ডেটা ভিউয়ার ব্যবহার করুন।

এছাড়াও, আপনি "get" পদ্ধতি ব্যবহার করে সম্পূর্ণ সংগ্রহ ফিরিয়ে আনতে পারবেন।

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
মনে রাখবেন: এই প্রোডাক্ট watchOS এবং অ্যাপ ক্লিপ টার্গেটে উপলভ্য নয়।
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());
                }
            }
        });

পাইপলাইন অপারেশন ব্যবহার করে ডেটা পড়া

এখন আপনি পাইপলাইন কোয়েরি অভিজ্ঞতার সাথে কোর কোয়েরি অভিজ্ঞতার তুলনা করতে পারবেন।

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);
    }
});

মোবাইল ও ওয়েব SDK-এর জন্য আপনার ডেটা সুরক্ষিত রাখুন

আপনি যদি ওয়েব, Android বা Apple প্ল্যাটফর্ম SDK ব্যবহার করেন, তাহলে Cloud Firestore-এ আপনার ডেটা সুরক্ষিত করতে Firebase Authentication এবং Cloud Firestore Security Rules ব্যবহার করুন।

শুরু করার জন্য আপনি ব্যবহার করতে পারেন এমন কিছু প্রাথমিক নিয়মের সেট এখানে দেওয়া হল। আপনি Firebase কনসোল থেকে ডেটাবেস ও স্টোরেজ > Firestore > নিয়ম ট্যাব বিকল্পে গিয়ে নিরাপত্তা সংক্রান্ত নিয়মাবলী পরিবর্তন করতে পারবেন।

যাচাইকরণ প্রয়োজন

// 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;
    }
  }
}

প্রোডাকশন মোড

// Deny read/write access to all users under any conditions
service cloud.firestore {
  match /databases/{database}/documents {
    match /{document=**} {
      allow read, write: if false;
    }
  }
}

আপনার ওয়েব, Android বা iOS অ্যাপ প্রোডাকশনে ডেপ্লয় করার আগে, আপনার অ্যাপ ক্লায়েন্টরা যাতে আপনার Cloud Firestore ডেটা অ্যাক্সেস করতে পারে তা নিশ্চিত করার জন্য পদক্ষেপ নিন। App Check ডকুমেন্টেশন দেখুন।

আপনি যদি কোনও সার্ভার SDK ব্যবহার করেন, তাহলে Cloud Firestore-এ আপনার ডেটা সুরক্ষিত করতে Identity and Access Management (IAM) ব্যবহার করুন।

পরবর্তী ধাপ

নিম্নলিখিত বিষয়গুলি থেকে Core ও Pipeline অপারেশন সম্পর্কে আপনার জ্ঞান আরও গভীর করুন:

  • মূল অপারেশন-এর মাধ্যমে কোয়েরি করা সম্পর্কে আরও জানুন
  • পাইপলাইন অপারেশন-এর মাধ্যমে কোয়েরি করা সম্পর্কে আরও জানুন।
  • আরও কার্যকরভাবে টাস্ক এক্সিকিউট করতে এবং Firebase এজেন্ট সংক্রান্ত দক্ষতার সাথে Cloud Firestore-এর পেশাদার পদ্ধতি (যেমন, Cloud Firestore Security Rules লেখা) ব্যবহার করতে, আপনার AI ডেভেলপমেন্ট টুল কীভাবে উন্নত করবেন তা জানুন।