Cloud Firestore का इस्तेमाल शुरू करना

इस क्विकस्टार्ट में, Cloud Firestore को सेट अप करने, डेटा जोड़ने, और Firebase कंसोल में जोड़े गए डेटा को देखने का तरीका बताया गया है.

Cloud Firestore डेटाबेस बनाएं

  1. अगर आपने पहले से Firebase प्रोजेक्ट नहीं बनाया है, तो अब बनाएं: Firebase कंसोल में प्रोजेक्ट जोड़ें पर क्लिक करें. इसके बाद, Firebase प्रोजेक्ट बनाने या किसी मौजूदा GCP प्रोजेक्ट में Firebase सेवाएं जोड़ने के लिए, स्क्रीन पर दिए गए निर्देशों का पालन करें.

  2. Firebase कंसोल के Cloud Firestore सेक्शन पर जाएं. आपको मौजूदा Firebase प्रोजेक्ट चुनने के लिए कहा जाएगा. डेटाबेस बनाने के वर्कफ़्लो को फ़ॉलो करें.

  3. अपने Cloud Firestore के सुरक्षा नियमों के लिए, कोई शुरुआती मोड चुनें:

    टेस्ट मोड

    यह मोबाइल और वेब क्लाइंट लाइब्रेरी के साथ शुरू करने के लिए बढ़िया है, लेकिन यह किसी को भी आपका डेटा पढ़ने और उसे ओवरराइट करने की सुविधा देती है. जांच करने के बाद, अपना डेटा सुरक्षित करें सेक्शन को ज़रूर देखें.

    वेब, Apple प्लैटफ़ॉर्म या Android SDK का इस्तेमाल शुरू करने के लिए, टेस्ट मोड चुनें.

    लॉक मोड

    मोबाइल और वेब क्लाइंट की ओर से कुछ भी पढ़ने और लिखने की अनुमति नहीं देता. आपके पुष्टि किए गए ऐप्लिकेशन सर्वर (C#, Go, Java, Node.js, PHP, Python या Ruby) अब भी आपके डेटाबेस को ऐक्सेस कर सकते हैं.

    C#, Go, Java, Node.js, PHP, Python या Ruby सर्वर क्लाइंट लाइब्रेरी का इस्तेमाल शुरू करने के लिए, लॉक मोड चुनें.

    Cloud Firestore के सुरक्षा नियमों का शुरुआती सेट, आपके डिफ़ॉल्ट Cloud Firestore डेटाबेस पर लागू होगा. अगर अपने प्रोजेक्ट के लिए एक से ज़्यादा डेटाबेस बनाए जाते हैं, तो हर डेटाबेस के लिए Cloud Firestore के सुरक्षा नियमों को डिप्लॉय किया जा सकता है.

  4. अपने डेटाबेस के लिए कोई जगह चुनें.

    • जगह की यह सेटिंग, आपके प्रोजेक्ट के लिए, Google Cloud Platform (GCP) के संसाधन की डिफ़ॉल्ट जगह होती है. ध्यान दें, इस जगह का इस्तेमाल आपके प्रोजेक्ट में GCP सेवाओं के लिए किया जाएगा. जिनके लिए जगह की जानकारी की सेटिंग ज़रूरी होती है, खास तौर पर, डिफ़ॉल्ट Cloud Storage बकेट और आपका App Engine ऐप्लिकेशन (यह तब ज़रूरी होता है, जब Cloud शेड्यूलर का इस्तेमाल किया जाता है).

    • अगर जगह चुनने में समस्या आ रही है, तो आपके प्रोजेक्ट में पहले से ही डिफ़ॉल्ट GCP संसाधन लोकेशन है. इसे या तो प्रोजेक्ट बनाते समय या ऐसी अन्य सेवा सेट अप करते समय सेट किया गया था जिसके लिए जगह की जानकारी की ज़रूरत होती है.

  5. हो गया पर क्लिक करें.

जब आप Cloud Firestore को चालू करते हैं, तो यह Cloud API मैनेजर में एपीआई को भी चालू कर देता है.

डेवलपमेंट एनवायरमेंट सेट अप करना

अपने ऐप्लिकेशन में ज़रूरी डिपेंडेंसी और क्लाइंट लाइब्रेरी जोड़ें.

वेब नेमस्पेस किया गया एपीआई

  1. Firebase को अपने वेब ऐप्लिकेशन में जोड़ने के लिए, निर्देशों का पालन करें.
  2. अपने ऐप्लिकेशन में Firebase और Cloud Firestore लाइब्रेरी जोड़ें:
    <script src="https://www.gstatic.com/firebasejs/10.11.1/firebase-app-compat.js"></script>
    <script src="https://www.gstatic.com/firebasejs/10.11.1/firebase-firestore-compat.js"></script>
    Cloud Firestore SDK एक एनपीएम पैकेज के तौर पर भी उपलब्ध है.
    npm install firebase@10.11.1 --save
    
    आपको मैन्युअल तरीके से Firebase और Cloud Firestore, दोनों की ज़रूरत होगी.
    import firebase from "firebase/compat/app";
    // Required for side-effects
    import "firebase/firestore";
    

वेब मॉड्यूलर एपीआई

  1. Firebase को अपने वेब ऐप्लिकेशन में जोड़ने के लिए, निर्देशों का पालन करें.
  2. Cloud Firestore SDK टूल, एनपीएम पैकेज के तौर पर उपलब्ध है.
    npm install firebase@10.11.1 --save
    
    आपको Firebase और Cloud Firestore, दोनों को इंपोर्ट करना होगा.
    import { initializeApp } from "firebase/app";
    import { getFirestore } from "firebase/firestore";
    
iOS+

अपने Apple ऐप्लिकेशन में Firebase जोड़ने के लिए, दिए गए निर्देशों का पालन करें.

Firebase डिपेंडेंसी इंस्टॉल और मैनेज करने के लिए, Swift Package Manager का इस्तेमाल करें.

  1. Xcode में, आपका ऐप्लिकेशन प्रोजेक्ट खुला होने पर, फ़ाइल > Swift Packages > Package Dependency जोड़ें पर जाएं.
  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:33.0.0"))
    
        // 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:25.0.0")
    }
    

    Kotlin की मदद से खास तौर पर बना लाइब्रेरी मॉड्यूल चाहिए? अक्टूबर 2023 की रिलीज़ से, Kotlin और Java डेवलपर, दोनों के डेवलपर मुख्य लाइब्रेरी मॉड्यूल पर निर्भर हो सकते हैं (ज़्यादा जानकारी के लिए, इस पहल के बारे में अक्सर पूछे जाने वाले सवाल देखें).

Dart

  1. अगर आपने पहले से ऐसा नहीं किया है, तो अपने Flutter ऐप्लिकेशन में Firebase को कॉन्फ़िगर और शुरू करें.
  2. प्लग इन को इंस्टॉल करने के लिए, अपने Flutter प्रोजेक्ट के रूट से, नीचे दिया गया कमांड चलाएं:
    flutter pub add cloud_firestore
  3. पूरा होने के बाद, अपने Flutter ऐप्लिकेशन को फिर से बनाएं:
    flutter run
  4. ज़रूरी नहीं: पहले से कंपाइल किए गए फ़्रेमवर्क को शामिल करके, iOS और macOS के बिल्ड प्रोसेस में लगने वाला समय बेहतर बनाएं.

    फ़िलहाल, iOS के लिए Firestore SDK टूल, उस कोड पर निर्भर है जिसे Xcode में बनने में पांच मिनट से ज़्यादा समय लग सकता है. बिल्ड में लगने वाले समय को काफ़ी कम करने के लिए, अपने Podfile में इस लाइन को target 'Runner' do ब्लॉक में जोड़कर, पहले से कंपाइल किए गए वर्शन का इस्तेमाल किया जा सकता है:

    target 'Runner' do
      use_frameworks!
      use_modular_headers!
    
      pod 'FirebaseFirestore',
        :git => 'https://github.com/invertase/firestore-ios-sdk-frameworks.git',
        :tag => 'IOS_SDK_VERSION'
    
      flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
      target 'RunnerTests' do
        inherit! :search_paths
      end
    end

    IOS_SDK_VERSION को Firebase iOS SDK टूल के उस वर्शन से बदलें जो firebase_core की firebase_sdk_version.rb फ़ाइल में बताया गया है. अगर firebase_core के नए वर्शन का इस्तेमाल नहीं किया जा रहा है, तो यह फ़ाइल अपने लोकल Pub पैकेज कैश मेमोरी (आम तौर पर ~/.pub-cache) में खोजें.

    इसके अलावा, पक्का करें कि आपने CocoaPods को 1.9.1 या उसके बाद के वर्शन पर अपग्रेड कर लिया है:

    gem install cocoapods

    ज़्यादा जानकारी के लिए, GitHub पर समस्या देखें.

Java
  1. अपने ऐप्लिकेशन में Firebase एडमिन SDK टूल जोड़ें:
    • Gredle का इस्तेमाल करके:
      compile 'com.google.firebase:firebase-admin:1.32.0'
      
    • Maven का इस्तेमाल करना:
      <dependency>
        <groupId>com.google.firebase</groupId>
        <artifactId>firebase-admin</artifactId>
        <version>1.32.0</version>
      </dependency>
           
  2. अपने एनवायरमेंट में सही क्रेडेंशियल के साथ Cloud Firestore शुरू करने के लिए, नीचे दिए गए निर्देशों का पालन करें.
Python
  1. अपने Python ऐप्लिकेशन में Firebase एडमिन SDK टूल जोड़ें:
    pip install --upgrade firebase-admin
  2. अपने एनवायरमेंट में सही क्रेडेंशियल के साथ Cloud Firestore शुरू करने के लिए, नीचे दिए गए निर्देशों का पालन करें.
C++
  1. अपने C++ प्रोजेक्ट में Firebase जोड़ने के लिए, निर्देशों का पालन करें.
  2. Android के लिए C++ इंटरफ़ेस.
    • ग्रेडल डिपेंडेंसी. अपने मॉड्यूल (ऐप्लिकेशन-लेवल) में Gradle फ़ाइल (आम तौर पर app/build.gradle) जोड़ें:
              android.defaultConfig.externalNativeBuild.cmake {
                arguments "-DFIREBASE_CPP_SDK_DIR=$gradle.firebase_cpp_sdk_dir"
              }
      
              apply from: "$gradle.firebase_cpp_sdk_dir/Android/firebase_dependencies.gradle"
              firebaseCpp.dependencies {
                // earlier entries
                auth
                firestore
              }
              
    • बाइनरी डिपेंडेंसी. इसी तरह, बाइनरी डिपेंडेंसी पाने के लिए, सुझाया गया तरीका यह है कि आप अपनी CMakeLists.txt फ़ाइल में इन्हें जोड़ें:
              add_subdirectory(${FIREBASE_CPP_SDK_DIR} bin/ EXCLUDE_FROM_ALL)
              set(firebase_libs firebase_auth firebase_firestore firebase_app)
              # Replace the target name below with the actual name of your target,
              # for example, "native-lib".
              target_link_libraries(${YOUR_TARGET_NAME_HERE} "${firebase_libs}")
              
  3. डेस्कटॉप इंटिग्रेशन सेट अप करने के लिए, अपने C++ प्रोजेक्ट में Firebase जोड़ना लेख पढ़ें.
Unity
  1. अपने Unity प्रोजेक्ट में Firebase जोड़ने के लिए, निर्देशों का पालन करें.
  2. Unity इंटरफ़ेस का इस्तेमाल करके, Android बिल्ड को छोटा करने के लिए अपना प्रोजेक्ट कॉन्फ़िगर करें.
  3. Error while merging dex archives मैसेज से बचने के लिए, आपको बिल्ड को छोटा करना होगा.

    • यह विकल्प देखने के लिए, प्लेयर सेटिंग > Android > पब्लिश करने की सेटिंग > छोटा करें में जाएं.
    • Unity के अलग-अलग वर्शन में, विकल्प अलग-अलग हो सकते हैं. इसलिए, Unity का आधिकारिक दस्तावेज़ और Firebase Unity बिल्ड डीबग गाइड देखें.
    • अगर छोटा करने की सुविधा चालू करने के बाद भी, रेफ़रंस वाले तरीकों की संख्या तय सीमा से ज़्यादा हो जाती है, तो multidex को इनमें से भी चालू किया जा सकता है:
      • mainTemplate.gradle, अगर प्लेयर सेटिंग में कस्टम ग्रेडल टेंप्लेट चालू है
      • या मॉड्यूल लेवल की build.gradle फ़ाइल. अगर एक्सपोर्ट किया गया प्रोजेक्ट बनाने के लिए Android Studio का इस्तेमाल किया जाता है.
Node.js के लिए
  1. अपने ऐप्लिकेशन में Firebase एडमिन SDK टूल जोड़ें:
    npm install firebase-admin --save
  2. अपने एनवायरमेंट में सही क्रेडेंशियल के साथ Cloud Firestore शुरू करने के लिए, नीचे दिए गए निर्देशों का पालन करें.
शुरू करें
  1. अपने Go ऐप्लिकेशन में Firebase एडमिन SDK टूल जोड़ें:
    go get firebase.google.com/go
    
  2. अपने एनवायरमेंट में सही क्रेडेंशियल के साथ Cloud Firestore शुरू करने के लिए, नीचे दिए गए निर्देशों का पालन करें.
PHP
  1. Cloud Firestore सर्वर क्लाइंट लाइब्रेरी (Java, Node.js, Python, Go, PHP, C#, और Ruby) पुष्टि करने के लिए, Google ऐप्लिकेशन डिफ़ॉल्ट क्रेडेंशियल का इस्तेमाल करती हैं.
    • अपने डेवलपमेंट एनवायरमेंट से पुष्टि करने के लिए, GOOGLE_APPLICATION_CREDENTIALS एनवायरमेंट वैरिएबल को इस तरह सेट करें कि वह JSON सेवा खाता कुंजी फ़ाइल पर ले जाए. आपके पास एपीआई कंसोल क्रेडेंशियल पेज पर जाकर, मुख्य फ़ाइल बनाने का विकल्प होता है.
      export GOOGLE_APPLICATION_CREDENTIALS="path/to/your/keyfile.json"
    • अपने प्रोडक्शन एनवायरमेंट में, अगर आप Cloud Firestore के लिए इस्तेमाल किए जाने वाले प्रोजेक्ट का इस्तेमाल करके App Engine या Compute Engine पर अपना ऐप्लिकेशन चलाते हैं, तो आपको पुष्टि करने की ज़रूरत नहीं है. इसके अलावा, कोई और सेवा खाता सेट अप करें.
  2. PHP के लिए gRPC एक्सटेंशन इंस्टॉल और चालू करें, इसके लिए आपको क्लाइंट लाइब्रेरी का इस्तेमाल करना होगा.
  3. अपने ऐप्लिकेशन में Cloud Firestore PHP लाइब्रेरी जोड़ें:
    composer require google/cloud-firestore
C#
  1. Cloud Firestore सर्वर क्लाइंट लाइब्रेरी (Java, Node.js, Python, Go, PHP, C#, और Ruby) पुष्टि करने के लिए, Google ऐप्लिकेशन डिफ़ॉल्ट क्रेडेंशियल का इस्तेमाल करती हैं.
    • अपने डेवलपमेंट एनवायरमेंट से पुष्टि करने के लिए, GOOGLE_APPLICATION_CREDENTIALS एनवायरमेंट वैरिएबल को इस तरह सेट करें कि वह JSON सेवा खाता कुंजी फ़ाइल पर ले जाए. आपके पास एपीआई कंसोल क्रेडेंशियल पेज पर जाकर, मुख्य फ़ाइल बनाने का विकल्प होता है.
      export GOOGLE_APPLICATION_CREDENTIALS="path/to/your/keyfile.json"
    • अपने प्रोडक्शन एनवायरमेंट में, अगर आप Cloud Firestore के लिए इस्तेमाल किए जाने वाले प्रोजेक्ट का इस्तेमाल करके App Engine या Compute Engine पर अपना ऐप्लिकेशन चलाते हैं, तो आपको पुष्टि करने की ज़रूरत नहीं है. इसके अलावा, कोई और सेवा खाता सेट अप करें.
  2. अपनी .csproj फ़ाइल के ऐप्लिकेशन में, Cloud Firestore C# लाइब्रेरी जोड़ें:
    <ItemGroup>
      <PackageReference Include="Google.Cloud.Firestore" Version="1.1.0-beta01" />
    </ItemGroup>
  3. अपनी Program.cs फ़ाइल में यह जोड़ें:
    using Google.Cloud.Firestore;
Ruby
  1. Cloud Firestore सर्वर क्लाइंट लाइब्रेरी (Java, Node.js, Python, Go, PHP, C#, और Ruby) पुष्टि करने के लिए, Google ऐप्लिकेशन डिफ़ॉल्ट क्रेडेंशियल का इस्तेमाल करती हैं.
    • अपने डेवलपमेंट एनवायरमेंट से पुष्टि करने के लिए, GOOGLE_APPLICATION_CREDENTIALS एनवायरमेंट वैरिएबल को इस तरह सेट करें कि वह JSON सेवा खाता कुंजी फ़ाइल पर ले जाए. आपके पास एपीआई कंसोल क्रेडेंशियल पेज पर जाकर, मुख्य फ़ाइल बनाने का विकल्प होता है.
      export GOOGLE_APPLICATION_CREDENTIALS="path/to/your/keyfile.json"
    • अपने प्रोडक्शन एनवायरमेंट में, अगर आप Cloud Firestore के लिए इस्तेमाल किए जाने वाले प्रोजेक्ट का इस्तेमाल करके App Engine या Compute Engine पर अपना ऐप्लिकेशन चलाते हैं, तो आपको पुष्टि करने की ज़रूरत नहीं है. इसके अलावा, कोई और सेवा खाता सेट अप करें.
  2. अपने Gemfile के ऐप्लिकेशन में Cloud Firestore Ruby लाइब्रेरी जोड़ें:
    gem "google-cloud-firestore"
  3. इनका इस्तेमाल करके, अपने Gemfile से डिपेंडेंसी इंस्टॉल करें:
    bundle install

(ज़रूरी नहीं) Firebase लोकल एम्युलेटर सुइट की मदद से प्रोटोटाइप और टेस्ट करना

मोबाइल डेवलपर के लिए, Cloud Firestore में आपके ऐप्लिकेशन को कैसे सेव और पढ़ा जाता है, इस बारे में बात करने से पहले, आइए टूल का एक सेट पेश करते हैं. इनका इस्तेमाल करके, Cloud Firestore के काम को प्रोटोटाइप और टेस्ट किया जा सकता है: Firebase लोकल एम्युलेटर सुइट. अगर डेटा के अलग-अलग मॉडल, अपने सुरक्षा नियमों को ऑप्टिमाइज़ किया जा रहा है या बैक-एंड के साथ इंटरैक्ट करने का सबसे किफ़ायती तरीका ढूंढने के लिए काम किया जा रहा है, तो लाइव सेवाओं को डिप्लॉय किए बिना, स्थानीय तौर पर काम करना एक बेहतरीन आइडिया हो सकता है.

Cloud Firestore एम्युलेटर, Local Emulator Suite का हिस्सा है. इसकी मदद से आपका ऐप्लिकेशन, एम्युलेट किए गए डेटाबेस के कॉन्टेंट और कॉन्फ़िगरेशन के साथ-साथ आपके एम्युलेट किए गए प्रोजेक्ट के संसाधनों (फ़ंक्शन, दूसरे डेटाबेस, और सुरक्षा के नियम) के साथ इंटरैक्ट कर सकता है.

Cloud Firestore एम्युलेटर का इस्तेमाल करने के लिए, आपको सिर्फ़ कुछ चरण पूरे करने होंगे:

  1. एम्युलेटर से कनेक्ट करने के लिए, आपके ऐप्लिकेशन के टेस्ट कॉन्फ़िगरेशन में एक लाइन का कोड जोड़ा जा रहा है.
  2. आपकी लोकल प्रोजेक्ट डायरेक्ट्री के रूट से, firebase emulators:start चल रहा है.
  3. हमेशा की तरह, Cloud Firestore प्लैटफ़ॉर्म SDK टूल का इस्तेमाल करके, अपने ऐप्लिकेशन के प्रोटोटाइप कोड से कॉल करना.

Cloud Firestore और Cloud Functions से जुड़े कदम-दर-कदम निर्देश उपलब्ध हैं. आपको लोकल एम्युलेटर सुइट के बारे में जानकारी भी देखनी चाहिए.

Cloud Firestore को शुरू करें

Cloud Firestore के इंस्टेंस को शुरू करें:

वेब मॉड्यूलर एपीआई

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 से बदलें.

डिवाइस का कनेक्शन टूट जाने पर डेटा को बनाए रखने के लिए, ऑफ़लाइन डेटा चालू करें दस्तावेज़ देखें.

वेब नेमस्पेस किया गया एपीआई

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 से बदलें.

डिवाइस का कनेक्शन टूट जाने पर डेटा को बनाए रखने के लिए, ऑफ़लाइन डेटा चालू करें दस्तावेज़ देखें.

स्विफ़्ट
ध्यान दें: यह प्रॉडक्ट, WatchOS और App Clip टारगेट पर उपलब्ध नहीं है.
import FirebaseCore
import FirebaseFirestore
FirebaseApp.configure()

let db = Firestore.firestore()
मकसद-सी
ध्यान दें: यह प्रॉडक्ट, WatchOS और App Clip टारगेट पर उपलब्ध नहीं है.
@import FirebaseCore;
@import FirebaseFirestore;

// Use Firebase library to configure APIs
[FIRApp configure];
  
FIRFirestore *defaultFirestore = [FIRFirestore firestore];

Kotlin+KTX

// Access a Cloud Firestore instance from your Activity
val db = Firebase.firestore

Java

// Access a Cloud Firestore instance from your Activity
FirebaseFirestore db = FirebaseFirestore.getInstance();

Dart

db = FirebaseFirestore.instance;
Java
Cloud Firestore SDK टूल को आपके एनवायरमेंट के हिसाब से अलग-अलग तरीकों से शुरू किया जाता है. नीचे सबसे सामान्य तरीके दिए गए हैं. पूरी जानकारी के लिए, एडमिन SDK शुरू करना देखें.
  • Google Cloud पर शुरू करें
    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 शुरू करना देखें.
  • Google Cloud पर शुरू करें
    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 शुरू करना देखें.
  • Google Cloud पर शुरू करें
    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()
  • C++
    // Make sure the call to `Create()` happens some time before you call Firestore::GetInstance().
    App::Create();
    Firestore* db = Firestore::GetInstance();
    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();
      
    शुरू करें
    Cloud Firestore SDK टूल को आपके एनवायरमेंट के हिसाब से अलग-अलग तरीकों से शुरू किया जाता है. नीचे सबसे सामान्य तरीके दिए गए हैं. पूरी जानकारी के लिए, एडमिन SDK शुरू करना देखें.
  • Google Cloud पर शुरू करें
    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 क्लाइंट को इंस्टॉल करने और बनाने के बारे में ज़्यादा जानकारी के लिए, Cloud Firestore क्लाइंट लाइब्रेरी देखें.

    use Google\Cloud\Firestore\FirestoreClient;
    
    /**
     * Initialize Cloud Firestore with default project ID.
     */
    function setup_client_create(string $projectId = null)
    {
        // Create the Cloud Firestore client
        if (empty($projectId)) {
            // The `projectId` parameter is optional and represents which project the
            // client will act on behalf of. If not supplied, the client falls back to
            // the default project inferred from the environment.
            $db = new FirestoreClient();
            printf('Created Cloud Firestore client with default project ID.' . PHP_EOL);
        } else {
            $db = new FirestoreClient([
                'projectId' => $projectId,
            ]);
            printf('Created Cloud Firestore client with project ID: %s' . PHP_EOL, $projectId);
        }
    }
    Unity
    using Firebase.Firestore;
    using Firebase.Extensions;
    FirebaseFirestore db = FirebaseFirestore.DefaultInstance;
    C#

    C#

    Cloud Firestore क्लाइंट को इंस्टॉल करने और बनाने के बारे में ज़्यादा जानकारी के लिए, Cloud Firestore क्लाइंट लाइब्रेरी देखें.

    FirestoreDb db = FirestoreDb.Create(project);
    Console.WriteLine("Created Cloud Firestore client with project ID: {0}", project);
    Ruby
    require "google/cloud/firestore"
    
    # The `project_id` parameter is optional and represents which project the
    # client will act on behalf of. If not supplied, the client falls back to the
    # default project inferred from the environment.
    firestore = Google::Cloud::Firestore.new project_id: project_id
    
    puts "Created Cloud Firestore client with given project ID."

    डेटा जोड़ें

    Cloud Firestore, दस्तावेज़ों में आपका डेटा सेव करता है, जो कलेक्शन में सेव किया जाता है. जब आप दस्तावेज़ में पहली बार डेटा जोड़ते हैं, तो Cloud Firestore बिना किसी रुकावट के कलेक्शन और दस्तावेज़ बनाता है. आपको अलग से कलेक्शन या दस्तावेज़ बनाने की ज़रूरत नहीं है.

    उदाहरण वाले नीचे दिए गए कोड का इस्तेमाल करके, एक नया कलेक्शन और दस्तावेज़ बनाएं.

    वेब मॉड्यूलर एपीआई

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

    वेब नेमस्पेस किया गया एपीआई

    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 और App Clip टारगेट पर उपलब्ध नहीं है.
    // 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)")
    }
    Objective-C
    ध्यान दें: यह प्रॉडक्ट, WatchOS और App Clip टारगेट पर उपलब्ध नहीं है.
    // Add a new document with a generated ID
    __block FIRDocumentReference *ref =
        [[self.db collectionWithPath:@"users"] addDocumentWithData:@{
          @"first": @"Ada",
          @"last": @"Lovelace",
          @"born": @1815
        } completion:^(NSError * _Nullable error) {
          if (error != nil) {
            NSLog(@"Error adding document: %@", error);
          } else {
            NSLog(@"Document added with ID: %@", ref.documentID);
          }
        }];

    Kotlin+KTX

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

    Dart

    // Create a new user with a first and last name
    final user = <String, dynamic>{
      "first": "Ada",
      "last": "Lovelace",
      "born": 1815
    };
    
    // Add a new document with a generated ID
    db.collection("users").add(user).then((DocumentReference doc) =>
        print('DocumentSnapshot added with ID: ${doc.id}'));
    Java
    DocumentReference docRef = db.collection("users").document("alovelace");
    // Add document data  with id "alovelace" using a hashmap
    Map<String, Object> data = new HashMap<>();
    data.put("first", "Ada");
    data.put("last", "Lovelace");
    data.put("born", 1815);
    //asynchronously write data
    ApiFuture<WriteResult> result = docRef.set(data);
    // ...
    // result.get() blocks on response
    System.out.println("Update time : " + result.get().getUpdateTime());
    Python
    doc_ref = db.collection("users").document("alovelace")
    doc_ref.set({"first": "Ada", "last": "Lovelace", "born": 1815})

    Python

    doc_ref = db.collection("users").document("alovelace")
    await doc_ref.set({"first": "Ada", "last": "Lovelace", "born": 1815})
    C++
    // Add a new document with a generated ID
    Future<DocumentReference> user_ref =
        db->Collection("users").Add({{"first", FieldValue::String("Ada")},
                                     {"last", FieldValue::String("Lovelace")},
                                     {"born", FieldValue::Integer(1815)}});
    
    user_ref.OnCompletion([](const Future<DocumentReference>& future) {
      if (future.error() == Error::kErrorOk) {
        std::cout << "DocumentSnapshot added with ID: " << future.result()->id()
                  << std::endl;
      } else {
        std::cout << "Error adding document: " << future.error_message() << std::endl;
      }
    });
    Node.js के लिए
    const docRef = db.collection('users').doc('alovelace');
    
    await docRef.set({
      first: 'Ada',
      last: 'Lovelace',
      born: 1815
    });
    शुरू करें
    _, _, err := client.Collection("users").Add(ctx, map[string]interface{}{
    	"first": "Ada",
    	"last":  "Lovelace",
    	"born":  1815,
    })
    if err != nil {
    	log.Fatalf("Failed adding alovelace: %v", err)
    }
    PHP

    PHP

    Cloud Firestore क्लाइंट को इंस्टॉल करने और बनाने के बारे में ज़्यादा जानकारी के लिए, Cloud Firestore क्लाइंट लाइब्रेरी देखें.

    $docRef = $db->collection('samples/php/users')->document('alovelace');
    $docRef->set([
        'first' => 'Ada',
        'last' => 'Lovelace',
        'born' => 1815
    ]);
    printf('Added data to the lovelace document in the users collection.' . PHP_EOL);
    Unity
    DocumentReference docRef = db.Collection("users").Document("alovelace");
    Dictionary<string, object> user = new Dictionary<string, object>
    {
    	{ "First", "Ada" },
    	{ "Last", "Lovelace" },
    	{ "Born", 1815 },
    };
    docRef.SetAsync(user).ContinueWithOnMainThread(task => {
    	Debug.Log("Added data to the alovelace document in the users collection.");
    });
    C#
    DocumentReference docRef = db.Collection("users").Document("alovelace");
    Dictionary<string, object> user = new Dictionary<string, object>
    {
        { "First", "Ada" },
        { "Last", "Lovelace" },
        { "Born", 1815 }
    };
    await docRef.SetAsync(user);
    Ruby
    doc_ref = firestore.doc "#{collection_path}/alovelace"
    
    doc_ref.set(
      {
        first: "Ada",
        last:  "Lovelace",
        born:  1815
      }
    )
    
    puts "Added data to the alovelace document in the users collection."

    अब users कलेक्शन में एक और दस्तावेज़ जोड़ें. ध्यान दें कि इस दस्तावेज़ में एक ऐसा की-वैल्यू पेयर (बीच का नाम) शामिल है जो पहले दस्तावेज़ में नहीं दिखता है. कलेक्शन के दस्तावेज़ों में अलग-अलग तरह की जानकारी हो सकती है.

    वेब मॉड्यूलर एपीआई

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

    वेब नेमस्पेस किया गया एपीआई

    // 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 और App Clip टारगेट पर उपलब्ध नहीं है.
    // 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)")
    }
    Objective-C
    ध्यान दें: यह प्रॉडक्ट, WatchOS और App Clip टारगेट पर उपलब्ध नहीं है.
    // Add a second document with a generated ID.
    __block FIRDocumentReference *ref =
        [[self.db collectionWithPath:@"users"] addDocumentWithData:@{
          @"first": @"Alan",
          @"middle": @"Mathison",
          @"last": @"Turing",
          @"born": @1912
        } completion:^(NSError * _Nullable error) {
          if (error != nil) {
            NSLog(@"Error adding document: %@", error);
          } else {
            NSLog(@"Document added with ID: %@", ref.documentID);
          }
        }];

    Kotlin+KTX

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

    Dart

    // Create a new user with a first and last name
    final user = <String, dynamic>{
      "first": "Alan",
      "middle": "Mathison",
      "last": "Turing",
      "born": 1912
    };
    
    // Add a new document with a generated ID
    db.collection("users").add(user).then((DocumentReference doc) =>
        print('DocumentSnapshot added with ID: ${doc.id}'));
    Java
    DocumentReference docRef = db.collection("users").document("aturing");
    // Add document data with an additional field ("middle")
    Map<String, Object> data = new HashMap<>();
    data.put("first", "Alan");
    data.put("middle", "Mathison");
    data.put("last", "Turing");
    data.put("born", 1912);
    
    ApiFuture<WriteResult> result = docRef.set(data);
    System.out.println("Update time : " + result.get().getUpdateTime());
    Python
    doc_ref = db.collection("users").document("aturing")
    doc_ref.set({"first": "Alan", "middle": "Mathison", "last": "Turing", "born": 1912})

    Python

    doc_ref = db.collection("users").document("aturing")
    await doc_ref.set(
        {"first": "Alan", "middle": "Mathison", "last": "Turing", "born": 1912}
    )
    C++
    db->Collection("users")
        .Add({{"first", FieldValue::String("Alan")},
              {"middle", FieldValue::String("Mathison")},
              {"last", FieldValue::String("Turing")},
              {"born", FieldValue::Integer(1912)}})
        .OnCompletion([](const Future<DocumentReference>& future) {
          if (future.error() == Error::kErrorOk) {
            std::cout << "DocumentSnapshot added with ID: "
                      << future.result()->id() << std::endl;
          } else {
            std::cout << "Error adding document: " << future.error_message()
                      << std::endl;
          }
        });
    Node.js के लिए
    const aTuringRef = db.collection('users').doc('aturing');
    
    await aTuringRef.set({
      'first': 'Alan',
      'middle': 'Mathison',
      'last': 'Turing',
      'born': 1912
    });
    शुरू करें
    _, _, err = client.Collection("users").Add(ctx, map[string]interface{}{
    	"first":  "Alan",
    	"middle": "Mathison",
    	"last":   "Turing",
    	"born":   1912,
    })
    if err != nil {
    	log.Fatalf("Failed adding aturing: %v", err)
    }
    PHP

    PHP

    Cloud Firestore क्लाइंट को इंस्टॉल करने और बनाने के बारे में ज़्यादा जानकारी के लिए, Cloud Firestore क्लाइंट लाइब्रेरी देखें.

    $docRef = $db->collection('samples/php/users')->document('aturing');
    $docRef->set([
        'first' => 'Alan',
        'middle' => 'Mathison',
        'last' => 'Turing',
        'born' => 1912
    ]);
    printf('Added data to the aturing document in the users collection.' . PHP_EOL);
    Unity
    DocumentReference docRef = db.Collection("users").Document("aturing");
    Dictionary<string, object> user = new Dictionary<string, object>
    {
    	{ "First", "Alan" },
    	{ "Middle", "Mathison" },
    	{ "Last", "Turing" },
    	{ "Born", 1912 }
    };
    docRef.SetAsync(user).ContinueWithOnMainThread(task => {
    	Debug.Log("Added data to the aturing document in the users collection.");
    });
    C#
    DocumentReference docRef = db.Collection("users").Document("aturing");
    Dictionary<string, object> user = new Dictionary<string, object>
    {
        { "First", "Alan" },
        { "Middle", "Mathison" },
        { "Last", "Turing" },
        { "Born", 1912 }
    };
    await docRef.SetAsync(user);
    Ruby
    doc_ref = firestore.doc "#{collection_path}/aturing"
    
    doc_ref.set(
      {
        first:  "Alan",
        middle: "Mathison",
        last:   "Turing",
        born:   1912
      }
    )
    
    puts "Added data to the aturing document in the users collection."

    डेटा पढ़ने की अनुमति दें

    आपने Cloud Firestore में डेटा जोड़ा है या नहीं, इसकी पुष्टि तुरंत करने के लिए, Firebase कंसोल में डेटा व्यूअर का इस्तेमाल करें.

    पूरे कलेक्शन को वापस पाने के लिए, "get" तरीके का इस्तेमाल भी किया जा सकता है.

    वेब मॉड्यूलर एपीआई

    import { collection, getDocs } from "firebase/firestore"; 
    
    const querySnapshot = await getDocs(collection(db, "users"));
    querySnapshot.forEach((doc) => {
      console.log(`${doc.id} => ${doc.data()}`);
    });

    वेब नेमस्पेस किया गया एपीआई

    db.collection("users").get().then((querySnapshot) => {
        querySnapshot.forEach((doc) => {
            console.log(`${doc.id} => ${doc.data()}`);
        });
    });
    Swift
    ध्यान दें: यह प्रॉडक्ट, WatchOS और App Clip टारगेट पर उपलब्ध नहीं है.
    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)")
    }
    Objective-C
    ध्यान दें: यह प्रॉडक्ट, WatchOS और App Clip टारगेट पर उपलब्ध नहीं है.
    [[self.db collectionWithPath:@"users"]
        getDocumentsWithCompletion:^(FIRQuerySnapshot * _Nullable snapshot,
                                     NSError * _Nullable error) {
          if (error != nil) {
            NSLog(@"Error getting documents: %@", error);
          } else {
            for (FIRDocumentSnapshot *document in snapshot.documents) {
              NSLog(@"%@ => %@", document.documentID, document.data);
            }
          }
        }];

    Kotlin+KTX

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

    Dart

    await db.collection("users").get().then((event) {
      for (var doc in event.docs) {
        print("${doc.id} => ${doc.data()}");
      }
    });
    Java
    // asynchronously retrieve all users
    ApiFuture<QuerySnapshot> query = db.collection("users").get();
    // ...
    // query.get() blocks on response
    QuerySnapshot querySnapshot = query.get();
    List<QueryDocumentSnapshot> documents = querySnapshot.getDocuments();
    for (QueryDocumentSnapshot document : documents) {
      System.out.println("User: " + document.getId());
      System.out.println("First: " + document.getString("first"));
      if (document.contains("middle")) {
        System.out.println("Middle: " + document.getString("middle"));
      }
      System.out.println("Last: " + document.getString("last"));
      System.out.println("Born: " + document.getLong("born"));
    }
    Python
    users_ref = db.collection("users")
    docs = users_ref.stream()
    
    for doc in docs:
        print(f"{doc.id} => {doc.to_dict()}")

    Python

    users_ref = db.collection("users")
    docs = users_ref.stream()
    
    async for doc in docs:
        print(f"{doc.id} => {doc.to_dict()}")
    C++
    Future<QuerySnapshot> users = db->Collection("users").Get();
    users.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 के लिए
    const snapshot = await db.collection('users').get();
    snapshot.forEach((doc) => {
      console.log(doc.id, '=>', doc.data());
    });
    शुरू करें
    iter := client.Collection("users").Documents(ctx)
    for {
    	doc, err := iter.Next()
    	if err == iterator.Done {
    		break
    	}
    	if err != nil {
    		log.Fatalf("Failed to iterate: %v", err)
    	}
    	fmt.Println(doc.Data())
    }
    PHP

    PHP

    Cloud Firestore क्लाइंट को इंस्टॉल करने और बनाने के बारे में ज़्यादा जानकारी के लिए, Cloud Firestore क्लाइंट लाइब्रेरी देखें.

    $usersRef = $db->collection('samples/php/users');
    $snapshot = $usersRef->documents();
    foreach ($snapshot as $user) {
        printf('User: %s' . PHP_EOL, $user->id());
        printf('First: %s' . PHP_EOL, $user['first']);
        if (!empty($user['middle'])) {
            printf('Middle: %s' . PHP_EOL, $user['middle']);
        }
        printf('Last: %s' . PHP_EOL, $user['last']);
        printf('Born: %d' . PHP_EOL, $user['born']);
        printf(PHP_EOL);
    }
    printf('Retrieved and printed out all documents from the users collection.' . PHP_EOL);
    Unity
    CollectionReference usersRef = db.Collection("users");
    usersRef.GetSnapshotAsync().ContinueWithOnMainThread(task =>
    {
      QuerySnapshot snapshot = task.Result;
      foreach (DocumentSnapshot document in snapshot.Documents)
      {
        Debug.Log(String.Format("User: {0}", document.Id));
        Dictionary<string, object> documentDictionary = document.ToDictionary();
        Debug.Log(String.Format("First: {0}", documentDictionary["First"]));
        if (documentDictionary.ContainsKey("Middle"))
        {
          Debug.Log(String.Format("Middle: {0}", documentDictionary["Middle"]));
        }
    
        Debug.Log(String.Format("Last: {0}", documentDictionary["Last"]));
        Debug.Log(String.Format("Born: {0}", documentDictionary["Born"]));
      }
    
      Debug.Log("Read all data from the users collection.");
    });
    C#
    CollectionReference usersRef = db.Collection("users");
    QuerySnapshot snapshot = await usersRef.GetSnapshotAsync();
    foreach (DocumentSnapshot document in snapshot.Documents)
    {
        Console.WriteLine("User: {0}", document.Id);
        Dictionary<string, object> documentDictionary = document.ToDictionary();
        Console.WriteLine("First: {0}", documentDictionary["First"]);
        if (documentDictionary.ContainsKey("Middle"))
        {
            Console.WriteLine("Middle: {0}", documentDictionary["Middle"]);
        }
        Console.WriteLine("Last: {0}", documentDictionary["Last"]);
        Console.WriteLine("Born: {0}", documentDictionary["Born"]);
        Console.WriteLine();
    }
    Ruby
    users_ref = firestore.col collection_path
    users_ref.get do |user|
      puts "#{user.document_id} data: #{user.data}."
    end

    अपना डेटा सुरक्षित रखें

    अगर वेब, Android या Apple प्लैटफ़ॉर्म SDK टूल का इस्तेमाल किया जा रहा है, तो Cloud Firestore में अपना डेटा सुरक्षित करने के लिए, Firebase से पुष्टि करने और Cloud 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 डेटा को सिर्फ़ आपके ऐप्लिकेशन क्लाइंट ऐक्सेस कर सकें. ऐप्लिकेशन की जांच से जुड़ा दस्तावेज़ देखें.

    अगर किसी एक सर्वर SDK टूल का इस्तेमाल किया जा रहा है, तो Cloud Firestore में अपना डेटा सुरक्षित करने के लिए, पहचान और ऐक्सेस मैनेजमेंट (आईएएम) का इस्तेमाल करें.

    वीडियो ट्यूटोरियल देखें

    Cloud Firestore मोबाइल क्लाइंट लाइब्रेरी के साथ शुरू करने के बारे में ज़्यादा जानकारी के लिए, इनमें से कोई एक वीडियो ट्यूटोरियल देखें:

    वेब
    iOS+
    Android

    ज़्यादा वीडियो देखने के लिए, Firebase YouTube चैनल पर जाएं.

    अगले चरण

    इन विषयों की मदद से अपना ज्ञान बढ़ाएं:

    • कोडलैबAndroid, iOS या वेब के लिए कोडलैब का पालन करके, Cloud Firestore को असल ऐप्लिकेशन में इस्तेमाल करने के बारे में जानें.
    • डेटा मॉडल — इस बारे में ज़्यादा जानें कि Cloud Firestore में डेटा को कैसे व्यवस्थित किया जाता है. इसमें हैरारकी वाला डेटा और सब-कलेक्शन भी शामिल हैं.
    • डेटा जोड़ें — Cloud Firestore में डेटा बनाने और अपडेट करने के बारे में ज़्यादा जानें.
    • डेटा पाना — डेटा वापस पाने के तरीके के बारे में ज़्यादा जानें.
    • आसान और जटिल क्वेरी करें — आसान और जटिल क्वेरी चलाने का तरीका जानें.
    • क्वेरी ऑर्डर करना और उसकी सीमा तय करना अपनी क्वेरी से मिले डेटा को ऑर्डर करने और उसे सीमित करने का तरीका जानें.