Cloud Firestore इंडेक्स की परिभाषा का रेफ़रंस

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

Firebase कंसोल में या सीएलआई का इस्तेमाल करके, कस्टम इंडेक्स बनाए जा सकते हैं, उनमें बदलाव किया जा सकता है, और डिप्लॉय किया जा सकता है. सीएलआई से, अपनी इंडेक्स कॉन्फ़िगरेशन फ़ाइल में डिफ़ॉल्ट फ़ाइल नाम firestore.indexes.json के साथ बदलाव करें और firebase deploy कमांड का इस्तेमाल करके डिप्लॉय करें.

firebase firestore:indexes का इस्तेमाल करके, सीएलआई की मदद से इंडेक्स एक्सपोर्ट किए जा सकते हैं.

इंडेक्स कॉन्फ़िगरेशन फ़ाइल, ऐसे ऑब्जेक्ट के बारे में बताती है जिसमें indexes अरे और एक वैकल्पिक fieldOverrides कलेक्शन मौजूद होता है. यहां एक उदाहरण दिया गया है:

{
  // Required, specify compound and vector indexes
  indexes: [
    {
      collectionGroup: "posts",
      queryScope: "COLLECTION",
      fields: [
        { fieldPath: "author", arrayConfig: "CONTAINS" },
        { fieldPath: "timestamp", order: "DESCENDING" }
      ]
    },
    {
      collectionGroup: "coffee-beans",
      queryScope: "COLLECTION",
      fields: [
        {
          fieldPath: "embedding_field",
          vectorConfig: { dimension: 256, flat: {} }
        }
      ]
    }
  ],

  // Optional, disable indexes or enable single-field collection group indexes
  fieldOverrides: [
    {
      collectionGroup: "posts",
      fieldPath: "myBigMapField",
      // We want to disable indexing on our big map field, and so empty the indexes array
      indexes: []
    }
  ]
}

इंडेक्स कॉन्फ़िगरेशन लागू करना

firebase deploy कमांड की मदद से, अपने इंडेक्स कॉन्फ़िगरेशन को डिप्लॉय करें. अगर आपको सिर्फ़ अपने प्रोजेक्ट में कॉन्फ़िगर किए गए डेटाबेस के लिए इंडेक्स डिप्लॉय करने हैं, तो --only firestore फ़्लैग जोड़ें. इस निर्देश के लिए विकल्प रेफ़रंस देखें.

डिप्लॉय किए गए इंडेक्स की सूची बनाने के लिए, firebase firestore:indexes कमांड चलाएं. अपने प्रोजेक्ट के डिफ़ॉल्ट डेटाबेस के अलावा, किसी दूसरे डेटाबेस के इंडेक्स की सूची बनाने के लिए, --database=<databaseID> फ़्लैग जोड़ें.

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

JSON फ़ॉर्मैट

इंडेक्स

indexes कलेक्शन में एक ऑब्जेक्ट के लिए स्कीमा यहां दिया गया है. वैकल्पिक प्रॉपर्टी की पहचान, ? वर्ण से की जाती है.

ध्यान दें कि Cloud Firestore के दस्तावेज़ फ़ील्ड सिर्फ़ एक मोड में इंडेक्स किए जा सकते हैं. इसलिए, किसी फ़ील्ड ऑब्जेक्ट में order, arrayConfig, और vectorConfig प्रॉपर्टी में से सिर्फ़ एक प्रॉपर्टी हो सकती है.

  collectionGroup: string  // Labeled "Collection ID" in the Firebase console
  queryScope: string       // One of "COLLECTION", "COLLECTION_GROUP"
  fields: array
    fieldPath: string
    order?: string         // One of "ASCENDING", "DESCENDING"; excludes arrayConfig and vectorConfig properties
    arrayConfig?: string   // If this parameter used, must be "CONTAINS"; excludes order and vectorConfig properties
    vectorConfig?: object  // Indicates that this is a vector index; excludes order and arrayConfig properties
      dimension: number    // The resulting index will only include vectors of this dimension
      flat: {}             // Indicates the vector index is a flat index

FieldOverrides

fieldOverrides कलेक्शन में एक ऑब्जेक्ट के लिए स्कीमा यहां दिया गया है. वैकल्पिक प्रॉपर्टी की पहचान, ? वर्ण से की जाती है.

ध्यान दें कि Cloud Firestore के दस्तावेज़ फ़ील्ड को सिर्फ़ एक मोड में इंडेक्स किया जा सकता है. इसलिए, किसी फ़ील्ड ऑब्जेक्ट में order और arrayConfig, दोनों प्रॉपर्टी नहीं हो सकतीं.

  collectionGroup: string  // Labeled "Collection ID" in the Firebase console
  fieldPath: string
  ttl?: boolean            // Set specified field to have TTL policy and be eligible for deletion
  indexes: array           // Use an empty array to disable indexes on this collectionGroup + fieldPath
    queryScope: string     // One of "COLLECTION", "COLLECTION_GROUP"
    order?: string         // One of "ASCENDING", "DESCENDING"; excludes arrayConfig property
    arrayConfig?: string   // If this parameter used, must be "CONTAINS"; excludes order property

TTL (टीटीएल) नीति

fieldOverrides कलेक्शन का इस्तेमाल करके, TTL (टीटीएल) नीति को इस तरह चालू या बंद किया जा सकता है:

  // Optional, disable index single-field collection group indexes
  fieldOverrides: [
    {
      collectionGroup: "posts",
      fieldPath: "ttlField",
      ttl: "true",  // Explicitly enable TTL on this Field.
      // Disable indexing so empty the indexes array
      indexes: []
    }
  ]

फ़ील्ड में डिफ़ॉल्ट इंडेक्स को बनाए रखने और TTL (टीटीएल) नीति चालू करने के लिए:

{
  "fieldOverrides": [
    {
      "collectionGroup": "yourCollectionGroup",
      "fieldPath": "yourFieldPath",
      "ttl": true,
      "indexes": [
        { "order": "ASCENDING", "queryScope": "COLLECTION_GROUP" },
        { "order": "DESCENDING", "queryScope": "COLLECTION_GROUP" },
        { "arrayConfig": "CONTAINS", "queryScope": "COLLECTION_GROUP" }
      ]
    }
  ]
}

टाइम-टू-लाइव (टीटीएल) की नीतियों के बारे में ज़्यादा जानने के लिए, आधिकारिक दस्तावेज़ देखें.