Cloud Firestore-এ স্টোর করা ডেটা ফিরিয়ে আনার তিনটি উপায় আছে। এই পদ্ধতিগুলির যেকোনও একটি ডকুমেন্ট, ডকুমেন্টের সংগ্রহ বা কোয়েরির ফলাফলের সাথে ব্যবহার করা যেতে পারে:
- একবার ডেটা পেতে কোনও পদ্ধতি কল করুন।
- ডেটা-পরিবর্তন ইভেন্ট পেতে লিসনার সেট করুন।
- ডেটা বান্ডেল-এর মাধ্যমে এক্সটার্নাল সোর্স থেকে Firestore স্ন্যাপশট ডেটা বাল্ক-লোড করুন। আরও বিবরণের জন্য বান্ডেল ডকুমেন্ট দেখুন।
আপনি কোনও লিসেনার সেট করলে, Cloud Firestore আপনার লিসেনারকে ডেটার একটি প্রাথমিক স্ন্যাপশট পাঠায় এবং তারপর ডকুমেন্ট পরিবর্তন হওয়ার প্রতিবার আরেকটি স্ন্যাপশট পাঠায়।
AI অ্যাসিস্ট্যান্সের জন্য AI প্রম্পট
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 retrieve and read data from Cloud Firestore in my app.
শুরু করার আগে
Cloud Firestore ডেটাবেস তৈরি করতে Cloud Firestore-এর সাথে শুরু করুন দেখুন।Cloud Firestore শুরু করুন
Cloud Firestore-এর একটি ইনস্ট্যান্স শুরু করুন:
মোবাইল ও ওয়েব SDK
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); // Initialize Cloud Firestore and get a reference to the service const db = getFirestore(app);
FIREBASE_CONFIGURATION-এর জায়গায় আপনার ওয়েব অ্যাপের
firebaseConfig লিখুন।
ডিভাইসের কানেকশন চলে গেলে ডেটা সেভ করে রাখতে, অফলাইন ডেটা চালু করুন ডকুমেন্টেশন দেখুন।
Web
import firebase from "firebase/app"; import "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 firebase.initializeApp(firebaseConfig); // Initialize Cloud Firestore and get a reference to the service const db = firebase.firestore();
FIREBASE_CONFIGURATION-এর জায়গায় আপনার ওয়েব অ্যাপের
firebaseConfig লিখুন।
ডিভাইসের কানেকশন চলে গেলে ডেটা সেভ করে রাখতে, অফলাইন ডেটা চালু করুন ডকুমেন্টেশন দেখুন।
Swift
import FirebaseCore import FirebaseFirestore
FirebaseApp.configure() let db = Firestore.firestore()
Objective-C
@import FirebaseCore; @import FirebaseFirestore; // Use Firebase library to configure APIs [FIRApp configure];
FIRFirestore *defaultFirestore = [FIRFirestore firestore];
Kotlin
// Access a Cloud Firestore instance from your Activityval db = Firebase.firestore
Java
// Access a Cloud Firestore instance from your ActivityFirebaseFirestore db = FirebaseFirestore.getInstance();
Dart
db = FirebaseFirestore.instance;
C++
// Make sure the call to `Create()` happens some time before you call Firestore::GetInstance(). App::Create(); Firestore* db = Firestore::GetInstance();
Unity
using Firebase.Firestore; using Firebase.Extensions;
FirebaseFirestore db = FirebaseFirestore.DefaultInstance;
সার্ভার ক্লায়েন্ট লাইব্রেরি
জাভা
আপনার এনভায়রনমেন্টের উপর নির্ভর করে Cloud Firestore SDK বিভিন্ন উপায়ে ইনিশিয়ালাইজ করা হয়। সবচেয়ে সাধারণ পদ্ধতিগুলি নিচে দেওয়া হল। সম্পূর্ণ রেফারেন্সের জন্য, অ্যাডমিন SDK ইনিশিয়ালাইজ করুন দেখুন।import com.google.auth.oauth2.GoogleCredentials; import com.google.cloud.firestore.Firestore; import com.google.firebase.FirebaseApp; import com.google.firebase.FirebaseOptions; // Use the application default credentials GoogleCredentials credentials = GoogleCredentials.getApplicationDefault(); FirebaseOptions options = new FirebaseOptions.Builder() .setCredentials(credentials) .setProjectId(projectId) .build(); FirebaseApp.initializeApp(options); Firestore db = FirestoreClient.getFirestore();
আপনার নিজের সার্ভারে Firebase অ্যাডমিন SDK ব্যবহার করতে, একটি পরিষেবা অ্যাকাউন্ট ব্যবহার করুন।
Google Cloud Console-এ IAM ও অ্যাডমিন > পরিষেবা অ্যাকাউন্ট বিকল্পে যান। নতুন ব্যক্তিগত কী তৈরি করে JSON ফাইল সেভ করুন। তারপর SDK শুরু করতে ফাইলটি ব্যবহার করুন:
import com.google.auth.oauth2.GoogleCredentials; import com.google.cloud.firestore.Firestore; import com.google.firebase.FirebaseApp; import com.google.firebase.FirebaseOptions; // Use a service account InputStream serviceAccount = new FileInputStream("path/to/serviceAccount.json"); GoogleCredentials credentials = GoogleCredentials.fromStream(serviceAccount); FirebaseOptions options = new FirebaseOptions.Builder() .setCredentials(credentials) .build(); FirebaseApp.initializeApp(options); Firestore db = FirestoreClient.getFirestore();
Python
আপনার এনভায়রনমেন্টের উপর নির্ভর করে Cloud Firestore SDK বিভিন্ন উপায়ে ইনিশিয়ালাইজ করা হয়। সবচেয়ে সাধারণ পদ্ধতিগুলি নিচে দেওয়া হল। সম্পূর্ণ রেফারেন্সের জন্য, অ্যাডমিন SDK ইনিশিয়ালাইজ করুন দেখুন।import firebase_admin from firebase_admin import firestore # Application Default credentials are automatically created. app = firebase_admin.initialize_app() db = firestore.client()
SDK শুরু করার জন্য আগে থেকে থাকা অ্যাপ্লিকেশন ডিফল্ট ক্রেডেনশিয়ালও ব্যবহার করা যেতে পারে।
import firebase_admin from firebase_admin import credentials from firebase_admin import firestore # Use the application default credentials. cred = credentials.ApplicationDefault() firebase_admin.initialize_app(cred) db = firestore.client()
আপনার নিজের সার্ভারে Firebase অ্যাডমিন SDK ব্যবহার করতে, একটি পরিষেবা অ্যাকাউন্ট ব্যবহার করুন।
Google Cloud Console-এ IAM ও অ্যাডমিন > পরিষেবা অ্যাকাউন্ট বিকল্পে যান। নতুন ব্যক্তিগত কী তৈরি করে JSON ফাইল সেভ করুন। তারপর SDK শুরু করতে ফাইলটি ব্যবহার করুন:
import firebase_admin from firebase_admin import credentials from firebase_admin import firestore # Use a service account. cred = credentials.Certificate('path/to/serviceAccount.json') app = firebase_admin.initialize_app(cred) db = firestore.client()
Python
আপনার এনভায়রনমেন্টের উপর নির্ভর করে Cloud Firestore SDK বিভিন্ন উপায়ে ইনিশিয়ালাইজ করা হয়। সবচেয়ে সাধারণ পদ্ধতিগুলি নিচে দেওয়া হল। সম্পূর্ণ রেফারেন্সের জন্য, অ্যাডমিন SDK ইনিশিয়ালাইজ করুন দেখুন।import firebase_admin from firebase_admin import firestore_async # Application Default credentials are automatically created. app = firebase_admin.initialize_app() db = firestore_async.client()
SDK শুরু করার জন্য আগে থেকে থাকা অ্যাপ্লিকেশন ডিফল্ট ক্রেডেনশিয়ালও ব্যবহার করা যেতে পারে।
import firebase_admin from firebase_admin import credentials from firebase_admin import firestore_async # Use the application default credentials. cred = credentials.ApplicationDefault() firebase_admin.initialize_app(cred) db = firestore_async.client()
আপনার নিজের সার্ভারে Firebase অ্যাডমিন SDK ব্যবহার করতে, একটি পরিষেবা অ্যাকাউন্ট ব্যবহার করুন।
Google Cloud Console-এ IAM ও অ্যাডমিন > পরিষেবা অ্যাকাউন্ট বিকল্পে যান। নতুন ব্যক্তিগত কী তৈরি করে JSON ফাইল সেভ করুন। তারপর SDK শুরু করতে ফাইলটি ব্যবহার করুন:
import firebase_admin from firebase_admin import credentials from firebase_admin import firestore_async # Use a service account. cred = credentials.Certificate('path/to/serviceAccount.json') app = firebase_admin.initialize_app(cred) db = firestore_async.client()
Node.js
আপনার এনভায়রনমেন্টের উপর নির্ভর করে Cloud Firestore SDK বিভিন্ন উপায়ে ইনিশিয়ালাইজ করা হয়। সবচেয়ে সাধারণ পদ্ধতিগুলি নিচে দেওয়া হল। সম্পূর্ণ রেফারেন্সের জন্য, অ্যাডমিন SDK ইনিশিয়ালাইজ করুন দেখুন।-
Cloud Functions-এ শুরু করুন
const { initializeApp, applicationDefault, cert } = require('firebase-admin/app'); const { getFirestore, Timestamp, FieldValue, Filter } = require('firebase-admin/firestore');
initializeApp(); const db = getFirestore();
-
Google Cloud-এ শুরু করুন
const { initializeApp, applicationDefault, cert } = require('firebase-admin/app'); const { getFirestore, Timestamp, FieldValue, Filter } = require('firebase-admin/firestore');
initializeApp({ credential: applicationDefault() }); const db = getFirestore();
-
আপনার নিজস্ব সার্ভারে ইনিশিয়ালাইজ করুন
আপনার নিজের সার্ভারে (বা অন্য কোনও Node.js এনভায়রনমেন্টে) Firebase অ্যাডমিন SDK ব্যবহার করতে, পরিষেবা অ্যাকাউন্ট ব্যবহার করুন। Google Cloud Console-এ IAM ও অ্যাডমিন > পরিষেবা অ্যাকাউন্ট বিকল্পে যান। নতুন ব্যক্তিগত কী তৈরি করে JSON ফাইল সেভ করুন। তারপর SDK শুরু করতে ফাইলটি ব্যবহার করুন:
const { initializeApp, applicationDefault, cert } = require('firebase-admin/app'); const { getFirestore, Timestamp, FieldValue, Filter } = require('firebase-admin/firestore');
const serviceAccount = require('./path/to/serviceAccountKey.json'); initializeApp({ credential: cert(serviceAccount) }); const db = getFirestore();
Go
আপনার এনভায়রনমেন্টের উপর নির্ভর করে Cloud Firestore SDK বিভিন্ন উপায়ে ইনিশিয়ালাইজ করা হয়। সবচেয়ে সাধারণ পদ্ধতিগুলি নিচে দেওয়া হল। সম্পূর্ণ রেফারেন্সের জন্য, অ্যাডমিন SDK ইনিশিয়ালাইজ করুন দেখুন।import ( "log" firebase "firebase.google.com/go" "google.golang.org/api/option" ) // Use the application default credentials ctx := context.Background() conf := &firebase.Config{ProjectID: projectID} app, err := firebase.NewApp(ctx, conf) if err != nil { log.Fatalln(err) } client, err := app.Firestore(ctx) if err != nil { log.Fatalln(err) } defer client.Close()
আপনার নিজের সার্ভারে Firebase অ্যাডমিন SDK ব্যবহার করতে, একটি পরিষেবা অ্যাকাউন্ট ব্যবহার করুন।
Google Cloud Console-এ IAM ও অ্যাডমিন > পরিষেবা অ্যাকাউন্ট বিকল্পে যান। নতুন ব্যক্তিগত কী তৈরি করে JSON ফাইল সেভ করুন। তারপর SDK শুরু করতে ফাইলটি ব্যবহার করুন:
import ( "log" firebase "firebase.google.com/go" "google.golang.org/api/option" ) // Use a service account ctx := context.Background() sa := option.WithCredentialsFile("path/to/serviceAccount.json") app, err := firebase.NewApp(ctx, nil, sa) if err != nil { log.Fatalln(err) } client, err := app.Firestore(ctx) if err != nil { log.Fatalln(err) } defer client.Close()
PHP
PHP
Cloud Firestore-এ যাচাইকরণ করতে, অ্যাপ্লিকেশন ডিফল্ট ক্রেডেনশিয়াল সেট-আপ করুন। আরও তথ্যের জন্য, লোকাল ডেভেলপমেন্ট এনভায়রনমেন্টের জন্য যাচাইকরণ সেট-আপ করুন দেখুন।
C#
C#
Cloud Firestore-এ যাচাইকরণ করতে, অ্যাপ্লিকেশন ডিফল্ট ক্রেডেনশিয়াল সেট-আপ করুন। আরও তথ্যের জন্য, লোকাল ডেভেলপমেন্ট এনভায়রনমেন্টের জন্য যাচাইকরণ সেট-আপ করুন দেখুন।
Ruby
উদাহরণ ডেটা
শুরু করতে, শহর সম্পর্কে কিছু ডেটা লিখুন যাতে আমরা এটি আবার পড়ার বিভিন্ন উপায় দেখতে পারি:
Web
import { collection, doc, setDoc } from "firebase/firestore"; const citiesRef = collection(db, "cities"); await setDoc(doc(citiesRef, "SF"), { name: "San Francisco", state: "CA", country: "USA", capital: false, population: 860000, regions: ["west_coast", "norcal"] }); await setDoc(doc(citiesRef, "LA"), { name: "Los Angeles", state: "CA", country: "USA", capital: false, population: 3900000, regions: ["west_coast", "socal"] }); await setDoc(doc(citiesRef, "DC"), { name: "Washington, D.C.", state: null, country: "USA", capital: true, population: 680000, regions: ["east_coast"] }); await setDoc(doc(citiesRef, "TOK"), { name: "Tokyo", state: null, country: "Japan", capital: true, population: 9000000, regions: ["kanto", "honshu"] }); await setDoc(doc(citiesRef, "BJ"), { name: "Beijing", state: null, country: "China", capital: true, population: 21500000, regions: ["jingjinji", "hebei"] });
Web
var citiesRef = db.collection("cities"); citiesRef.doc("SF").set({ name: "San Francisco", state: "CA", country: "USA", capital: false, population: 860000, regions: ["west_coast", "norcal"] }); citiesRef.doc("LA").set({ name: "Los Angeles", state: "CA", country: "USA", capital: false, population: 3900000, regions: ["west_coast", "socal"] }); citiesRef.doc("DC").set({ name: "Washington, D.C.", state: null, country: "USA", capital: true, population: 680000, regions: ["east_coast"] }); citiesRef.doc("TOK").set({ name: "Tokyo", state: null, country: "Japan", capital: true, population: 9000000, regions: ["kanto", "honshu"] }); citiesRef.doc("BJ").set({ name: "Beijing", state: null, country: "China", capital: true, population: 21500000, regions: ["jingjinji", "hebei"] });
Swift
let citiesRef = db.collection("cities") citiesRef.document("SF").setData([ "name": "San Francisco", "state": "CA", "country": "USA", "capital": false, "population": 860000, "regions": ["west_coast", "norcal"] ]) citiesRef.document("LA").setData([ "name": "Los Angeles", "state": "CA", "country": "USA", "capital": false, "population": 3900000, "regions": ["west_coast", "socal"] ]) citiesRef.document("DC").setData([ "name": "Washington D.C.", "country": "USA", "capital": true, "population": 680000, "regions": ["east_coast"] ]) citiesRef.document("TOK").setData([ "name": "Tokyo", "country": "Japan", "capital": true, "population": 9000000, "regions": ["kanto", "honshu"] ]) citiesRef.document("BJ").setData([ "name": "Beijing", "country": "China", "capital": true, "population": 21500000, "regions": ["jingjinji", "hebei"] ])
Objective-C
FIRCollectionReference *citiesRef = [self.db collectionWithPath:@"cities"]; [[citiesRef documentWithPath:@"SF"] setData:@{ @"name": @"San Francisco", @"state": @"CA", @"country": @"USA", @"capital": @(NO), @"population": @860000, @"regions": @[@"west_coast", @"norcal"] }]; [[citiesRef documentWithPath:@"LA"] setData:@{ @"name": @"Los Angeles", @"state": @"CA", @"country": @"USA", @"capital": @(NO), @"population": @3900000, @"regions": @[@"west_coast", @"socal"] }]; [[citiesRef documentWithPath:@"DC"] setData:@{ @"name": @"Washington D.C.", @"country": @"USA", @"capital": @(YES), @"population": @680000, @"regions": @[@"east_coast"] }]; [[citiesRef documentWithPath:@"TOK"] setData:@{ @"name": @"Tokyo", @"country": @"Japan", @"capital": @(YES), @"population": @9000000, @"regions": @[@"kanto", @"honshu"] }]; [[citiesRef documentWithPath:@"BJ"] setData:@{ @"name": @"Beijing", @"country": @"China", @"capital": @(YES), @"population": @21500000, @"regions": @[@"jingjinji", @"hebei"] }];
Kotlin
val cities = db.collection("cities") val data1 = hashMapOf( "name" to "San Francisco", "state" to "CA", "country" to "USA", "capital" to false, "population" to 860000, "regions" to listOf("west_coast", "norcal"), ) cities.document("SF").set(data1) val data2 = hashMapOf( "name" to "Los Angeles", "state" to "CA", "country" to "USA", "capital" to false, "population" to 3900000, "regions" to listOf("west_coast", "socal"), ) cities.document("LA").set(data2) val data3 = hashMapOf( "name" to "Washington D.C.", "state" to null, "country" to "USA", "capital" to true, "population" to 680000, "regions" to listOf("east_coast"), ) cities.document("DC").set(data3) val data4 = hashMapOf( "name" to "Tokyo", "state" to null, "country" to "Japan", "capital" to true, "population" to 9000000, "regions" to listOf("kanto", "honshu"), ) cities.document("TOK").set(data4) val data5 = hashMapOf( "name" to "Beijing", "state" to null, "country" to "China", "capital" to true, "population" to 21500000, "regions" to listOf("jingjinji", "hebei"), ) cities.document("BJ").set(data5)
Java
CollectionReference cities = db.collection("cities"); Map<String, Object> data1 = new HashMap<>(); data1.put("name", "San Francisco"); data1.put("state", "CA"); data1.put("country", "USA"); data1.put("capital", false); data1.put("population", 860000); data1.put("regions", Arrays.asList("west_coast", "norcal")); cities.document("SF").set(data1); Map<String, Object> data2 = new HashMap<>(); data2.put("name", "Los Angeles"); data2.put("state", "CA"); data2.put("country", "USA"); data2.put("capital", false); data2.put("population", 3900000); data2.put("regions", Arrays.asList("west_coast", "socal")); cities.document("LA").set(data2); Map<String, Object> data3 = new HashMap<>(); data3.put("name", "Washington D.C."); data3.put("state", null); data3.put("country", "USA"); data3.put("capital", true); data3.put("population", 680000); data3.put("regions", Arrays.asList("east_coast")); cities.document("DC").set(data3); Map<String, Object> data4 = new HashMap<>(); data4.put("name", "Tokyo"); data4.put("state", null); data4.put("country", "Japan"); data4.put("capital", true); data4.put("population", 9000000); data4.put("regions", Arrays.asList("kanto", "honshu")); cities.document("TOK").set(data4); Map<String, Object> data5 = new HashMap<>(); data5.put("name", "Beijing"); data5.put("state", null); data5.put("country", "China"); data5.put("capital", true); data5.put("population", 21500000); data5.put("regions", Arrays.asList("jingjinji", "hebei")); cities.document("BJ").set(data5);
Dart
final cities = db.collection("cities"); final data1 = <String, dynamic>{ "name": "San Francisco", "state": "CA", "country": "USA", "capital": false, "population": 860000, "regions": ["west_coast", "norcal"] }; cities.doc("SF").set(data1); final data2 = <String, dynamic>{ "name": "Los Angeles", "state": "CA", "country": "USA", "capital": false, "population": 3900000, "regions": ["west_coast", "socal"], }; cities.doc("LA").set(data2); final data3 = <String, dynamic>{ "name": "Washington D.C.", "state": null, "country": "USA", "capital": true, "population": 680000, "regions": ["east_coast"] }; cities.doc("DC").set(data3); final data4 = <String, dynamic>{ "name": "Tokyo", "state": null, "country": "Japan", "capital": true, "population": 9000000, "regions": ["kanto", "honshu"] }; cities.doc("TOK").set(data4); final data5 = <String, dynamic>{ "name": "Beijing", "state": null, "country": "China", "capital": true, "population": 21500000, "regions": ["jingjinji", "hebei"], }; cities.doc("BJ").set(data5);
জাভা
Python
class City: def __init__(self, name, state, country, capital=False, population=0, regions=[]): self.name = name self.state = state self.country = country self.capital = capital self.population = population self.regions = regions @staticmethod def from_dict(source): # ... def to_dict(self): # ... def __repr__(self): return f"City(\ name={self.name}, \ country={self.country}, \ population={self.population}, \ capital={self.capital}, \ regions={self.regions}\ )"
cities_ref = db.collection("cities") cities_ref.document("BJ").set( City("Beijing", None, "China", True, 21500000, ["hebei"]).to_dict() ) cities_ref.document("SF").set( City( "San Francisco", "CA", "USA", False, 860000, ["west_coast", "norcal"] ).to_dict() ) cities_ref.document("LA").set( City( "Los Angeles", "CA", "USA", False, 3900000, ["west_coast", "socal"] ).to_dict() ) cities_ref.document("DC").set( City("Washington D.C.", None, "USA", True, 680000, ["east_coast"]).to_dict() ) cities_ref.document("TOK").set( City("Tokyo", None, "Japan", True, 9000000, ["kanto", "honshu"]).to_dict() )
Python
C++
CollectionReference cities = db->Collection("cities"); cities.Document("SF").Set({ {"name", FieldValue::String("San Francisco")}, {"state", FieldValue::String("CA")}, {"country", FieldValue::String("USA")}, {"capital", FieldValue::Boolean(false)}, {"population", FieldValue::Integer(860000)}, {"regions", FieldValue::Array({FieldValue::String("west_coast"), FieldValue::String("norcal")})}, }); cities.Document("LA").Set({ {"name", FieldValue::String("Los Angeles")}, {"state", FieldValue::String("CA")}, {"country", FieldValue::String("USA")}, {"capital", FieldValue::Boolean(false)}, {"population", FieldValue::Integer(3900000)}, {"regions", FieldValue::Array({FieldValue::String("west_coast"), FieldValue::String("socal")})}, }); cities.Document("DC").Set({ {"name", FieldValue::String("Washington D.C.")}, {"state", FieldValue::Null()}, {"country", FieldValue::String("USA")}, {"capital", FieldValue::Boolean(true)}, {"population", FieldValue::Integer(680000)}, {"regions", FieldValue::Array({FieldValue::String("east_coast")})}, }); cities.Document("TOK").Set({ {"name", FieldValue::String("Tokyo")}, {"state", FieldValue::Null()}, {"country", FieldValue::String("Japan")}, {"capital", FieldValue::Boolean(true)}, {"population", FieldValue::Integer(9000000)}, {"regions", FieldValue::Array({FieldValue::String("kanto"), FieldValue::String("honshu")})}, }); cities.Document("BJ").Set({ {"name", FieldValue::String("Beijing")}, {"state", FieldValue::Null()}, {"country", FieldValue::String("China")}, {"capital", FieldValue::Boolean(true)}, {"population", FieldValue::Integer(21500000)}, {"regions", FieldValue::Array({FieldValue::String("jingjinji"), FieldValue::String("hebei")})}, });
Node.js
Go
PHP
PHP
Cloud Firestore-এ যাচাইকরণ করতে, অ্যাপ্লিকেশন ডিফল্ট ক্রেডেনশিয়াল সেট-আপ করুন। আরও তথ্যের জন্য, লোকাল ডেভেলপমেন্ট এনভায়রনমেন্টের জন্য যাচাইকরণ সেট-আপ করুন দেখুন।
Unity
CollectionReference citiesRef = db.Collection("cities"); citiesRef.Document("SF").SetAsync(new Dictionary<string, object>(){ { "Name", "San Francisco" }, { "State", "CA" }, { "Country", "USA" }, { "Capital", false }, { "Population", 860000 } }).ContinueWithOnMainThread(task => citiesRef.Document("LA").SetAsync(new Dictionary<string, object>(){ { "Name", "Los Angeles" }, { "State", "CA" }, { "Country", "USA" }, { "Capital", false }, { "Population", 3900000 } }) ).ContinueWithOnMainThread(task => citiesRef.Document("DC").SetAsync(new Dictionary<string, object>(){ { "Name", "Washington D.C." }, { "State", null }, { "Country", "USA" }, { "Capital", true }, { "Population", 680000 } }) ).ContinueWithOnMainThread(task => citiesRef.Document("TOK").SetAsync(new Dictionary<string, object>(){ { "Name", "Tokyo" }, { "State", null }, { "Country", "Japan" }, { "Capital", true }, { "Population", 9000000 } }) ).ContinueWithOnMainThread(task => citiesRef.Document("BJ").SetAsync(new Dictionary<string, object>(){ { "Name", "Beijing" }, { "State", null }, { "Country", "China" }, { "Capital", true }, { "Population", 21500000 } }) );
C#
Ruby
ডকুমেন্ট পান
get() ব্যবহার করে কীভাবে একটি ডকুমেন্টের কন্টেন্ট ফিরিয়ে আনা যায় তা নিম্নলিখিত উদাহরণে দেখানো হয়েছে:
Web
import { doc, getDoc } from "firebase/firestore"; const docRef = doc(db, "cities", "SF"); const docSnap = await getDoc(docRef); if (docSnap.exists()) { console.log("Document data:", docSnap.data()); } else { // docSnap.data() will be undefined in this case console.log("No such document!"); }
Web
var docRef = db.collection("cities").doc("SF"); docRef.get().then((doc) => { if (doc.exists) { console.log("Document data:", doc.data()); } else { // doc.data() will be undefined in this case console.log("No such document!"); } }).catch((error) => { console.log("Error getting document:", error); });
Swift
let docRef = db.collection("cities").document("SF") do { let document = try await docRef.getDocument() if document.exists { let dataDescription = document.data().map(String.init(describing:)) ?? "nil" print("Document data: \(dataDescription)") } else { print("Document does not exist") } } catch { print("Error getting document: \(error)") }
Objective-C
FIRDocumentReference *docRef = [[self.db collectionWithPath:@"cities"] documentWithPath:@"SF"]; [docRef getDocumentWithCompletion:^(FIRDocumentSnapshot *snapshot, NSError *error) { if (snapshot.exists) { // Document data may be nil if the document exists but has no keys or values. NSLog(@"Document data: %@", snapshot.data); } else { NSLog(@"Document does not exist"); } }];
Kotlin
val docRef = db.collection("cities").document("SF") docRef.get() .addOnSuccessListener { document -> if (document != null) { Log.d(TAG, "DocumentSnapshot data: ${document.data}") } else { Log.d(TAG, "No such document") } } .addOnFailureListener { exception -> Log.d(TAG, "get failed with ", exception) }
Java
DocumentReference docRef = db.collection("cities").document("SF"); docRef.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() { @Override public void onComplete(@NonNull Task<DocumentSnapshot> task) { if (task.isSuccessful()) { DocumentSnapshot document = task.getResult(); if (document.exists()) { Log.d(TAG, "DocumentSnapshot data: " + document.getData()); } else { Log.d(TAG, "No such document"); } } else { Log.d(TAG, "get failed with ", task.getException()); } } });
Dart
final docRef = db.collection("cities").doc("SF"); docRef.get().then( (DocumentSnapshot doc) { final data = doc.data() as Map<String, dynamic>; // ... }, onError: (e) => print("Error getting document: $e"), );
জাভা
Python
Python
C++
DocumentReference doc_ref = db->Collection("cities").Document("SF"); doc_ref.Get().OnCompletion([](const Future<DocumentSnapshot>& future) { if (future.error() == Error::kErrorOk) { const DocumentSnapshot& document = *future.result(); if (document.exists()) { std::cout << "DocumentSnapshot id: " << document.id() << std::endl; } else { std::cout << "no such document" << std::endl; } } else { std::cout << "Get failed with: " << future.error_message() << std::endl; } });
Node.js
Go
PHP
PHP
Cloud Firestore-এ যাচাইকরণ করতে, অ্যাপ্লিকেশন ডিফল্ট ক্রেডেনশিয়াল সেট-আপ করুন। আরও তথ্যের জন্য, লোকাল ডেভেলপমেন্ট এনভায়রনমেন্টের জন্য যাচাইকরণ সেট-আপ করুন দেখুন।
Unity
DocumentReference docRef = db.Collection("cities").Document("SF"); docRef.GetSnapshotAsync().ContinueWithOnMainThread(task => { DocumentSnapshot snapshot = task.Result; if (snapshot.Exists) { Debug.Log(String.Format("Document data for {0} document:", snapshot.Id)); Dictionary<string, object> city = snapshot.ToDictionary(); foreach (KeyValuePair<string, object> pair in city) { Debug.Log(String.Format("{0}: {1}", pair.Key, pair.Value)); } } else { Debug.Log(String.Format("Document {0} does not exist!", snapshot.Id)); } });
C#
Ruby
সোর্স সংক্রান্ত বিকল্প
অফলাইন সাপোর্ট সহ প্ল্যাটফর্মের জন্য, আপনি source বিকল্প সেট করতে পারেন যাতে
get কল কীভাবে অফলাইন ক্যাশে ব্যবহার করে তা নিয়ন্ত্রণ করা যায়।
ডিফল্ট হিসেবে, get কল আপনার ডেটাবেস থেকে লেটেস্ট ডকুমেন্ট স্ন্যাপশট ফেচ করার চেষ্টা করবে। অফলাইন সাপোর্ট সহ প্ল্যাটফর্মে, নেটওয়ার্ক উপলভ্য না থাকলে বা অনুরোধের সময়সীমা শেষ হয়ে গেলে, ক্লায়েন্ট লাইব্রেরি অফলাইন ক্যাশে ব্যবহার করবে।
ডিফল্ট অ্যাকশন পরিবর্তন করতে আপনি get() কলে source বিকল্প নির্দিষ্ট করতে
পারেন। আপনি শুধুমাত্র ডেটাবেস থেকে ফেচ করতে এবং অফলাইন ক্যাশে উপেক্ষা করতে পারেন অথবা আপনি শুধুমাত্র অফলাইন ক্যাশে থেকে ফেচ করতে পারেন। যেমন:
Web
import { doc, getDocFromCache } from "firebase/firestore"; const docRef = doc(db, "cities", "SF"); // Get a document, forcing the SDK to fetch from the offline cache. try { const doc = await getDocFromCache(docRef); // Document was found in the cache. If no cached document exists, // an error will be returned to the 'catch' block below. console.log("Cached document data:", doc.data()); } catch (e) { console.log("Error getting cached document:", e); }
Web
var docRef = db.collection("cities").doc("SF"); // Valid options for source are 'server', 'cache', or // 'default'. See https://firebase.google.com/docs/reference/js/v8/firebase.firestore.GetOptions // for more information. var getOptions = { source: 'cache' }; // Get a document, forcing the SDK to fetch from the offline cache. docRef.get(getOptions).then((doc) => { // Document was found in the cache. If no cached document exists, // an error will be returned to the 'catch' block below. console.log("Cached document data:", doc.data()); }).catch((error) => { console.log("Error getting cached document:", error); });
Swift
let docRef = db.collection("cities").document("SF") do { // Force the SDK to fetch the document from the cache. Could also specify // FirestoreSource.server or FirestoreSource.default. let document = try await docRef.getDocument(source: .cache) if document.exists { let dataDescription = document.data().map(String.init(describing:)) ?? "nil" print("Cached document data: \(dataDescription)") } else { print("Document does not exist in cache") } } catch { print("Error getting document: \(error)") }
Objective-C
FIRDocumentReference *docRef = [[self.db collectionWithPath:@"cities"] documentWithPath:@"SF"]; // Force the SDK to fetch the document from the cache. Could also specify // FIRFirestoreSourceServer or FIRFirestoreSourceDefault. [docRef getDocumentWithSource:FIRFirestoreSourceCache completion:^(FIRDocumentSnapshot *snapshot, NSError *error) { if (snapshot != NULL) { // The document data was found in the cache. NSLog(@"Cached document data: %@", snapshot.data); } else { // The document data was not found in the cache. NSLog(@"Document does not exist in cache: %@", error); } }];
Kotlin
val docRef = db.collection("cities").document("SF") // Source can be CACHE, SERVER, or DEFAULT. val source = Source.CACHE // Get the document, forcing the SDK to use the offline cache docRef.get(source).addOnCompleteListener { task -> if (task.isSuccessful) { // Document found in the offline cache val document = task.result Log.d(TAG, "Cached document data: ${document?.data}") } else { Log.d(TAG, "Cached get failed: ", task.exception) } }
Java
DocumentReference docRef = db.collection("cities").document("SF"); // Source can be CACHE, SERVER, or DEFAULT. Source source = Source.CACHE; // Get the document, forcing the SDK to use the offline cache docRef.get(source).addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() { @Override public void onComplete(@NonNull Task<DocumentSnapshot> task) { if (task.isSuccessful()) { // Document found in the offline cache DocumentSnapshot document = task.getResult(); Log.d(TAG, "Cached document data: " + document.getData()); } else { Log.d(TAG, "Cached get failed: ", task.getException()); } } });
Dart
final docRef = db.collection("cities").doc("SF"); // Source can be CACHE, SERVER, or DEFAULT. const source = Source.cache; docRef.get(const GetOptions(source: source)).then( (res) => print("Successfully completed"), onError: (e) => print("Error completing: $e"), );
জাভা
Java SDK-তে কাজ করে না।
Python
Python SDK-তে কাজ করে না।
C++
DocumentReference doc_ref = db->Collection("cities").Document("SF"); Source source = Source::kCache; doc_ref.Get(source).OnCompletion([](const Future<DocumentSnapshot>& future) { if (future.error() == Error::kErrorOk) { const DocumentSnapshot& document = *future.result(); if (document.exists()) { std::cout << "Cached document id: " << document.id() << std::endl; } else { } } else { std::cout << "Cached get failed: " << future.error_message() << std::endl; } });
Node.js
Node.js SDK-তে কাজ করে না।
Go
Go SDK-তে কাজ করে না।
PHP
PHP SDK-তে কাজ করে না।
Unity
Unity SDK-তে কাজ করে না।
C#
C# SDK-তে কাজ করে না।
Ruby
Ruby SDK-তে কাজ করে না।
কাস্টম অবজেক্ট
আগের উদাহরণে ম্যাপ হিসেবে ডকুমেন্টের কন্টেন্ট ফিরিয়ে আনা হয়েছে, তবে কিছু ভাষায় কাস্টম অবজেক্ট টাইপ ব্যবহার করা আরও সুবিধাজনক। ডেটা যোগ করুন বিকল্পে, আপনি একটি City ক্লাস
সংজ্ঞায়িত করেছেন যা আপনি প্রতিটি শহর সংজ্ঞায়িত করতে ব্যবহার করেছেন। আপনি নিজের ডকুমেন্টকে আবার City-এ
পরিবর্তন করতে পারবেন:
কাস্টম অবজেক্ট ব্যবহার করতে, আপনার ক্লাসের জন্য একটি FirestoreDataConverter ফাংশন নির্ধারণ করতে হবে। যেমন:
Web
class City { constructor (name, state, country ) { this.name = name; this.state = state; this.country = country; } toString() { return this.name + ', ' + this.state + ', ' + this.country; } } // Firestore data converter const cityConverter = { toFirestore: (city) => { return { name: city.name, state: city.state, country: city.country }; }, fromFirestore: (snapshot, options) => { const data = snapshot.data(options); return new City(data.name, data.state, data.country); } };
কাস্টম অবজেক্ট ব্যবহার করতে, আপনার ক্লাসের জন্য একটি FirestoreDataConverter ফাংশন নির্ধারণ করতে হবে। যেমন:
Web
class City { constructor (name, state, country ) { this.name = name; this.state = state; this.country = country; } toString() { return this.name + ', ' + this.state + ', ' + this.country; } } // Firestore data converter var cityConverter = { toFirestore: function(city) { return { name: city.name, state: city.state, country: city.country }; }, fromFirestore: function(snapshot, options){ const data = snapshot.data(options); return new City(data.name, data.state, data.country); } };
আপনার রিড অপারেশনের সাথে ডেটা কনভার্টারকে কল করুন। কনভার্ট করার পরে, আপনি কাস্টম অবজেক্ট পদ্ধতি অ্যাক্সেস করতে পারবেন:
Web
import { doc, getDoc} from "firebase/firestore"; const ref = doc(db, "cities", "LA").withConverter(cityConverter); const docSnap = await getDoc(ref); if (docSnap.exists()) { // Convert to City object const city = docSnap.data(); // Use a City instance method console.log(city.toString()); console.log(city.name, city.state, city.country); } else { console.log("No such document!"); }
আপনার রিড অপারেশনের সাথে ডেটা কনভার্টারকে কল করুন। কনভার্ট করার পরে, আপনি কাস্টম অবজেক্ট পদ্ধতি অ্যাক্সেস করতে পারবেন:
Web
db.collection("cities").doc("LA") .withConverter(cityConverter) .get().then((doc) => { if (doc.exists){ // Convert to City object var city = doc.data(); // Use a City instance method console.log(city.toString()); console.log(city.name, city.state, city.country); } else { console.log("No such document!"); }}).catch((error) => { console.log("Error getting document:", error); });
Swift
Swift-এ অটোমেটিক টাইপ সিরিয়ালাইজেশন সাপোর্ট করতে, আপনার টাইপ অবশ্যই Codable প্রোটোকল মেনে চলতে হবে।
let docRef = db.collection("cities").document("BJ") do { let city = try await docRef.getDocument(as: City.self) print("City: \(city)") } catch { print("Error decoding city: \(error)") }
Objective-C
Objective-C-তে আপনাকে এটি ম্যানুয়ালি করতে হবে।
FIRDocumentReference *docRef = [[self.db collectionWithPath:@"cities"] documentWithPath:@"BJ"]; [docRef getDocumentWithCompletion:^(FIRDocumentSnapshot *snapshot, NSError *error) { FSTCity *city = [[FSTCity alloc] initWithDictionary:snapshot.data]; if (city != nil) { NSLog(@"City: %@", city); } else { NSLog(@"Document does not exist"); } }];
Kotlin
val docRef = db.collection("cities").document("BJ") docRef.get().addOnSuccessListener { documentSnapshot -> val city = documentSnapshot.toObject<City>() }
Java
গুরুত্বপূর্ণ: প্রতিটি কাস্টম ক্লাসে অবশ্যই একটি পাবলিক কনস্ট্রাক্টর থাকতে হবে যা কোনও আর্গুমেন্ট নেয় না। এছাড়াও, ক্লাসে প্রতিটি প্রপার্টির জন্য একটি পাবলিক গেটার অন্তর্ভুক্ত করতে হবে।
DocumentReference docRef = db.collection("cities").document("BJ"); docRef.get().addOnSuccessListener(new OnSuccessListener<DocumentSnapshot>() { @Override public void onSuccess(DocumentSnapshot documentSnapshot) { City city = documentSnapshot.toObject(City.class); } });
Dart
কাস্টম অবজেক্ট ব্যবহার করতে, আপনার ক্লাসের জন্য Firestore ডেটা কনভার্সন ফাংশন সংজ্ঞায়িত করতে হবে। যেমন:
class City { final String? name; final String? state; final String? country; final bool? capital; final int? population; final List<String>? regions; City({ this.name, this.state, this.country, this.capital, this.population, this.regions, }); factory City.fromFirestore( DocumentSnapshot<Map<String, dynamic>> snapshot, SnapshotOptions? options, ) { final data = snapshot.data(); return City( name: data?['name'], state: data?['state'], country: data?['country'], capital: data?['capital'], population: data?['population'], regions: data?['regions'] is Iterable ? List.from(data?['regions']) : null, ); } Map<String, dynamic> toFirestore() { return { if (name != null) "name": name, if (state != null) "state": state, if (country != null) "country": country, if (capital != null) "capital": capital, if (population != null) "population": population, if (regions != null) "regions": regions, }; } }
তারপর, আপনার ডেটা কনভার্সন ফাংশনের সাথে একটি ডকুমেন্ট রেফারেন্স তৈরি করুন। এই রেফারেন্স ব্যবহার করে আপনি যে কোনও রিড অপারেশন করলে তা আপনার কাস্টম ক্লাসের ইনস্ট্যান্স রিটার্ন করবে:
final ref = db.collection("cities").doc("LA").withConverter( fromFirestore: City.fromFirestore, toFirestore: (City city, _) => city.toFirestore(), ); final docSnap = await ref.get(); final city = docSnap.data(); // Convert to City object if (city != null) { print(city); } else { print("No such document."); }
জাভা
প্রতিটি কাস্টম ক্লাসে একটি পাবলিক কনস্ট্রাক্টর থাকতে হবে যা কোনও আর্গুমেন্ট নেয় না। এছাড়াও, ক্লাসে প্রতিটি প্রপার্টির জন্য একটি পাবলিক গেটার অন্তর্ভুক্ত করতে হবে।
Python
Python
C++
// This is not yet supported.Node.js
Node.js জাভাস্ক্রিপ্ট অবজেক্ট ব্যবহার করে।
Go
PHP
PHP
Cloud Firestore-এ যাচাইকরণ করতে, অ্যাপ্লিকেশন ডিফল্ট ক্রেডেনশিয়াল সেট-আপ করুন। আরও তথ্যের জন্য, লোকাল ডেভেলপমেন্ট এনভায়রনমেন্টের জন্য যাচাইকরণ সেট-আপ করুন দেখুন।
Unity
DocumentReference docRef = db.Collection("cities").Document("BJ"); docRef.GetSnapshotAsync().ContinueWith((task) => { var snapshot = task.Result; if (snapshot.Exists) { Debug.Log(String.Format("Document data for {0} document:", snapshot.Id)); City city = snapshot.ConvertTo<City>(); Debug.Log(String.Format("Name: {0}", city.Name)); Debug.Log(String.Format("State: {0}", city.State)); Debug.Log(String.Format("Country: {0}", city.Country)); Debug.Log(String.Format("Capital: {0}", city.Capital)); Debug.Log(String.Format("Population: {0}", city.Population)); } else { Debug.Log(String.Format("Document {0} does not exist!", snapshot.Id)); } });
C#
Ruby
Ruby-এর জন্য প্রযোজ্য নয়।
কালেকশন থেকে একাধিক ডকুমেন্ট পাওয়া
এছাড়াও, আপনি একটি কালেকশনে ডকুমেন্ট কোয়েরি করে একটি অনুরোধের মাধ্যমে একাধিক ডকুমেন্ট
উদ্ধার করতে পারেন। যেমন, আপনি where() ব্যবহার করে এমন সব ডকুমেন্ট কোয়েরি করতে পারেন
যেগুলি নির্দিষ্ট শর্ত পূরণ করে, তারপর get() ব্যবহার করে ফলাফল
পেতে পারেন:
Web
import { collection, query, where, getDocs } from "firebase/firestore"; const q = query(collection(db, "cities"), where("capital", "==", true)); const querySnapshot = await getDocs(q); querySnapshot.forEach((doc) => { // doc.data() is never undefined for query doc snapshots console.log(doc.id, " => ", doc.data()); });
Web
db.collection("cities").where("capital", "==", true) .get() .then((querySnapshot) => { querySnapshot.forEach((doc) => { // doc.data() is never undefined for query doc snapshots console.log(doc.id, " => ", doc.data()); }); }) .catch((error) => { console.log("Error getting documents: ", error); });
Swift
do { let querySnapshot = try await db.collection("cities").whereField("capital", isEqualTo: true) .getDocuments() for document in querySnapshot.documents { print("\(document.documentID) => \(document.data())") } } catch { print("Error getting documents: \(error)") }
Objective-C
[[[self.db collectionWithPath:@"cities"] queryWhereField:@"capital" isEqualTo:@(YES)] getDocumentsWithCompletion:^(FIRQuerySnapshot *snapshot, NSError *error) { if (error != nil) { NSLog(@"Error getting documents: %@", error); } else { for (FIRDocumentSnapshot *document in snapshot.documents) { NSLog(@"%@ => %@", document.documentID, document.data); } } }];
Kotlin
db.collection("cities") .whereEqualTo("capital", true) .get() .addOnSuccessListener { documents -> for (document in documents) { Log.d(TAG, "${document.id} => ${document.data}") } } .addOnFailureListener { exception -> Log.w(TAG, "Error getting documents: ", exception) }
Java
db.collection("cities") .whereEqualTo("capital", true) .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.d(TAG, "Error getting documents: ", task.getException()); } } });
Dart
db.collection("cities").where("capital", isEqualTo: true).get().then( (querySnapshot) { print("Successfully completed"); for (var docSnapshot in querySnapshot.docs) { print('${docSnapshot.id} => ${docSnapshot.data()}'); } }, onError: (e) => print("Error completing: $e"), );
জাভা
Python
Python
C++
db->Collection("cities") .WhereEqualTo("capital", FieldValue::Boolean(true)) .Get() .OnCompletion([](const Future<QuerySnapshot>& future) { if (future.error() == Error::kErrorOk) { for (const DocumentSnapshot& document : future.result()->documents()) { std::cout << document << std::endl; } } else { std::cout << "Error getting documents: " << future.error_message() << std::endl; } });
Node.js
Go
PHP
PHP
Cloud Firestore-এ যাচাইকরণ করতে, অ্যাপ্লিকেশন ডিফল্ট ক্রেডেনশিয়াল সেট-আপ করুন। আরও তথ্যের জন্য, লোকাল ডেভেলপমেন্ট এনভায়রনমেন্টের জন্য যাচাইকরণ সেট-আপ করুন দেখুন।
Unity
Query capitalQuery = db.Collection("cities").WhereEqualTo("Capital", true); capitalQuery.GetSnapshotAsync().ContinueWithOnMainThread(task => { QuerySnapshot capitalQuerySnapshot = task.Result; foreach (DocumentSnapshot documentSnapshot in capitalQuerySnapshot.Documents) { Debug.Log(String.Format("Document data for {0} document:", documentSnapshot.Id)); Dictionary<string, object> city = documentSnapshot.ToDictionary(); foreach (KeyValuePair<string, object> pair in city) { Debug.Log(String.Format("{0}: {1}", pair.Key, pair.Value)); } // Newline to separate entries Debug.Log(""); }; });
C#
Ruby
ডিফল্ট হিসেবে, Cloud Firestore ডকুমেন্ট আইডি অনুযায়ী ছোট থেকে বড় ক্রমানুসারে কোয়েরি পূরণ করে এমন সব ডকুমেন্ট ফিরিয়ে আনে, তবে আপনি ফিরে আসা ডেটা অর্ডার ও সীমিত করতে পারবেন।
কালেকশনে সব ডকুমেন্ট পান
এছাড়াও, আপনি where() ফিল্টার সম্পূর্ণভাবে বাদ দিয়ে কোনও সংগ্রহের সব ডকুমেন্ট
উদ্ধার করতে পারবেন:
Web
import { collection, getDocs } from "firebase/firestore"; const querySnapshot = await getDocs(collection(db, "cities")); querySnapshot.forEach((doc) => { // doc.data() is never undefined for query doc snapshots console.log(doc.id, " => ", doc.data()); });
Web
db.collection("cities").get().then((querySnapshot) => { querySnapshot.forEach((doc) => { // doc.data() is never undefined for query doc snapshots console.log(doc.id, " => ", doc.data()); }); });
Swift
do { let querySnapshot = try await db.collection("cities").getDocuments() for document in querySnapshot.documents { print("\(document.documentID) => \(document.data())") } } catch { print("Error getting documents: \(error)") }
Objective-C
[[self.db collectionWithPath:@"cities"] getDocumentsWithCompletion:^(FIRQuerySnapshot *snapshot, NSError *error) { if (error != nil) { NSLog(@"Error getting documents: %@", error); } else { for (FIRDocumentSnapshot *document in snapshot.documents) { NSLog(@"%@ => %@", document.documentID, document.data); } } }];
Kotlin
db.collection("cities") .get() .addOnSuccessListener { result -> for (document in result) { Log.d(TAG, "${document.id} => ${document.data}") } } .addOnFailureListener { exception -> Log.d(TAG, "Error getting documents: ", exception) }
Java
db.collection("cities") .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.d(TAG, "Error getting documents: ", task.getException()); } } });
Dart
db.collection("cities").get().then( (querySnapshot) { print("Successfully completed"); for (var docSnapshot in querySnapshot.docs) { print('${docSnapshot.id} => ${docSnapshot.data()}'); } }, onError: (e) => print("Error completing: $e"), );
জাভা
Python
Python
C++
db->Collection("cities").Get().OnCompletion( [](const Future<QuerySnapshot>& future) { if (future.error() == Error::kErrorOk) { for (const DocumentSnapshot& document : future.result()->documents()) { std::cout << document << std::endl; } } else { std::cout << "Error getting documents: " << future.error_message() << std::endl; } });
Node.js
Go
PHP
PHP
Cloud Firestore-এ যাচাইকরণ করতে, অ্যাপ্লিকেশন ডিফল্ট ক্রেডেনশিয়াল সেট-আপ করুন। আরও তথ্যের জন্য, লোকাল ডেভেলপমেন্ট এনভায়রনমেন্টের জন্য যাচাইকরণ সেট-আপ করুন দেখুন।
Unity
Query allCitiesQuery = db.Collection("cities"); allCitiesQuery.GetSnapshotAsync().ContinueWithOnMainThread(task => { QuerySnapshot allCitiesQuerySnapshot = task.Result; foreach (DocumentSnapshot documentSnapshot in allCitiesQuerySnapshot.Documents) { Debug.Log(String.Format("Document data for {0} document:", documentSnapshot.Id)); Dictionary<string, object> city = documentSnapshot.ToDictionary(); foreach (KeyValuePair<string, object> pair in city) { Debug.Log(String.Format("{0}: {1}", pair.Key, pair.Value)); } // Newline to separate entries Debug.Log(""); } });
C#
Ruby
সাবকালেকশনে সব ডকুমেন্ট পান
সাবকালেকশন থেকে সব ডকুমেন্ট ফিরিয়ে আনতে, সেই সাবকালেকশনের সম্পূর্ণ পাথ সহ একটি রেফারেন্স তৈরি করুন:
Web
const { collection, getDocs } = require("firebase/firestore"); // Query a reference to a subcollection const querySnapshot = await getDocs(collection(db, "cities", "SF", "landmarks")); querySnapshot.forEach((doc) => { // doc.data() is never undefined for query doc snapshots console.log(doc.id, " => ", doc.data()); });
Web
// Snippet not available
Swift
do { let querySnapshot = try await db.collection("cities/SF/landmarks").getDocuments() for document in querySnapshot.documents { print("\(document.documentID) => \(document.data())") } } catch { print("Error getting documents: \(error)") }
Objective-C
[[self.db collectionWithPath:@"cities/SF/landmarks"] getDocumentsWithCompletion:^(FIRQuerySnapshot *snapshot, NSError *error) { if (error != nil) { NSLog(@"Error getting documents: %@", error); } else { for (FIRDocumentSnapshot *document in snapshot.documents) { NSLog(@"%@ => %@", document.documentID, document.data); } } }];
Kotlin
db.collection("cities") .document("SF") .collection("landmarks") .get() .addOnSuccessListener { result -> for (document in result) { Log.d(TAG, "${document.id} => ${document.data}") } } .addOnFailureListener { exception -> Log.d(TAG, "Error getting documents: ", exception) }
Java
db.collection("cities") .document("SF") .collection("landmarks") .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.d(TAG, "Error getting documents: ", task.getException()); } } });
Dart
db.collection("cities").doc("SF").collection("landmarks").get().then( (querySnapshot) { print("Successfully completed"); for (var docSnapshot in querySnapshot.docs) { print('${docSnapshot.id} => ${docSnapshot.data()}'); } }, onError: (e) => print("Error completing: $e"), );
জাভা
// Snippet not available
Python
// Snippet not available
Python
// Snippet not available
C++
// Snippet not available
Node.js
// Snippet not available
Go
// Snippet not available
PHP
// Snippet not available
Unity
// Snippet not available
C#
// Snippet not available
Ruby
// Snippet not available
কালেকশন গ্রুপ থেকে একাধিক ডকুমেন্ট পাওয়া
একই আইডি সহ সব কালেকশন নিয়ে একটি কালেকশন গ্রুপ তৈরি হয়। যেমন, আপনার cities সংগ্রহের প্রতিটি ডকুমেন্টে যদি landmarks নামে একটি উপ-সংগ্রহ থাকে, তাহলে সব landmarks উপ-সংগ্রহ একই সংগ্রহ গ্রুপের অন্তর্গত। ডিফল্ট হিসেবে, কোয়েরি আপনার ডেটাবেসের একটি একক সংগ্রহ থেকে ফলাফল
উদ্ধার করে। একটি একক সংগ্রহ থেকে ফলাফল পাওয়ার পরিবর্তে একটি সংগ্রহ গ্রুপ থেকে ফলাফল পেতে একটি সংগ্রহ গ্রুপ কোয়েরি ব্যবহার করুন।
কোনও ডকুমেন্টের সাবকালেকশন তালিকাভুক্ত করুন
Cloud Firestore সার্ভার ক্লায়েন্ট লাইব্রেরির listCollections() পদ্ধতি
ডকুমেন্ট রেফারেন্সের সব সাব-কালেকশন তালিকাভুক্ত করে।
মোবাইল/ওয়েব ক্লায়েন্ট লাইব্রেরির মাধ্যমে সংগ্রহের তালিকা ফিরিয়ে আনা সম্ভব নয়। বিশ্বস্ত সার্ভার এনভায়রনমেন্টে প্রশাসনিক কাজের অংশ হিসেবে আপনার শুধু সংগ্রহের নাম খোঁজা উচিত। আপনি যদি দেখেন যে মোবাইল/ওয়েব ক্লায়েন্ট লাইব্রেরিতে আপনার এই ক্ষমতা প্রয়োজন, তাহলে আপনার ডেটা পুনর্গঠন করার কথা বিবেচনা করুন যাতে সাবকালেকশনের নাম অনুমান করা যায়।
ওয়েব
ওয়েব ক্লায়েন্ট লাইব্রেরিতে উপলভ্য নয়।
Swift
Swift ক্লায়েন্ট লাইব্রেরিতে উপলভ্য নয়।
Objective-C
Objective-C ক্লায়েন্ট লাইব্রেরিতে উপলভ্য নয়।
Kotlin
Android ক্লায়েন্ট লাইব্রেরিতে উপলভ্য নয়।
Java
Android ক্লায়েন্ট লাইব্রেরিতে উপলভ্য নয়।
Dart
Flutter ক্লায়েন্ট লাইব্রেরিতে উপলভ্য নয়।
জাভা
Python
Python
C++
C++ ক্লায়েন্ট লাইব্রেরিতে উপলভ্য নয়।
Node.js
Go
PHP
PHP
Cloud Firestore-এ যাচাইকরণ করতে, অ্যাপ্লিকেশন ডিফল্ট ক্রেডেনশিয়াল সেট-আপ করুন। আরও তথ্যের জন্য, লোকাল ডেভেলপমেন্ট এনভায়রনমেন্টের জন্য যাচাইকরণ সেট-আপ করুন দেখুন।
Unity
// This is not yet supported in the Unity SDK.C#
Ruby
বিভিন্ন ধরনের কোয়েরি সম্পর্কে আরও জানুন।
ডেটা পাওয়ার সময় সমস্যার কোড এবং লেটেন্সি সংক্রান্ত সমস্যা কীভাবে সমাধান করবেন সেই সম্পর্কে আরও তথ্য পেতে, সমস্যার সমাধানকরণ পৃষ্ঠা দেখুন।