取得範本

在特定的收集資源上執行 GET 擷取的屬性集合。

注意

這些 API 參考文章示範如何使用 Azure Cosmos DB 資料平面 API 來建立資源。 使用資料平面 API,您可以設定基本選項,例如編制索引原則,分割區索引鍵與使用 Cosmos DB SDK 非常類似。 如果您需要所有 Azure Cosmos DB 資源的完整功能支援,建議您使用 Cosmos DB 資源提供者

要求

方法 要求 URI 描述
GET HTTPs://{databaseaccount}.documents.azure.com/dbs/{db-id}/colls/{coll-id} {databaseaccount} 是您訂用帳戶下建立的 Azure Cosmos DB 帳戶名稱。 {db-id} 值是使用者產生的資料庫名稱/識別碼,而不是系統產生的識別碼 (rid) 。 {coll-id} 值是集合的名稱。

標題

如需所有 Cosmos DB 要求所使用的標頭,請參閱 常見的 Azure Cosmos DB REST 要求標頭

主體

無。

回應

Get Collection 會傳回在 Cosmos DB 中保存的集合主體,以及報告集合配額和使用方式的回應標頭。

標題

如需所有 Cosmos DB 回應所傳回的標頭,請參閱 常見的 Azure Cosmos DB REST 回應標頭

狀態碼

下表列出此作業所傳回的常見狀態碼。 如需狀態碼的完整清單,請參閱 HTTP 狀態碼

HTTP 狀態碼 Description
200 確定 作業成功。
404 找不到 集合不再是資源,也就是集合已刪除。

主體

屬性 描述
id 這是識別新集合的唯一名稱。
_擺脫 這是系統產生的屬性。 資源識別碼 (_rid) 是資源模型上每個資源堆疊也是階層式的唯一識別碼。 供內部進行放置和導覽文件資源時使用。
_Ts 這是系統產生的屬性。 代表資源的上次更新時間戳記。 值為時間戳記。
_自我 這是系統產生的屬性。 代表資源的唯一可定址 URI。
_Etag 這是系統產生的屬性,代表開放式並行控制所需的資源 etag
_醫生 這是系統產生的屬性,可指定檔資源的可定址路徑。
_sprocs 這是系統產生的屬性,指定預存程式的可定址路徑, (sprocs) 資源。
_觸發器 這是系統產生的屬性,指定觸發程式資源的可定址路徑。
_udfs 這是系統產生的屬性,指定使用者定義函式 (udfs) 資源的可定址路徑。
_衝突 這是系統產生的屬性,指定衝突資源的可定址路徑。 在操作集合內的資源期間,如果發生衝突,使用者可以在衝突 URI 路徑上執行 GET 來檢查衝突的資源。
indexingPolicy 這是集合的索引編制原則設定。

索引編制原則下的屬性

屬性 Description
自動 指出是否自動索引為開啟或關閉。 預設值為 True,因此會編制所有檔的索引。 值設為 False 允許手動設定檢索路徑。
indexingMode 根據預設,索引模式為 [一致]。 這表示在插入、取代或刪除檔時,會同步進行索引編制。 若要非同步進行檢索,請將檢索模式設為 lazy。
includedPaths 包含要檢索的文件路徑的陣列。 根據預設,會包含兩個路徑:指定所有檔路徑編制索引的 / 路徑,以及用來比較時間戳記範圍之索引的_ts路徑。

在陣列中的 元素內。

[包含路徑] 底下的屬性

屬性 Description
path 套用索引行為的路徑。 索引路徑開頭為根 (/) ,且通常會以問號 (?) 萬用字元運算子結尾,表示前置詞有多個可能的值。 例如,若要為 SELECT * FROM Families F WHERE F.familyName = "Andersen" 提供服務,您必須在集合的索引原則中包含 /familyName/? 的索引路徑。

索引路徑也可以使用 * 萬用字元運算子來指定路徑首碼底下的遞迴行為。 例如,使用 /payload/* 可將 payload 屬性下的所有項目自編製索引作業中排除。
dataType 這是套用索引行為的資料類型。 可以是 StringNumberPointPolygonLineString。 布林值和 Null 會自動編制索引
kind 索引的類型。 雜湊 索引適用于相等比較,而 範圍 索引適用于相等、範圍比較和排序。 空間 索引對於空間查詢很有用。
有效位數 索引的有效位數。 可以設定為 -1 表示最大有效位數,或 數位介於 1-8 之間,而 String可以設定為 1-100。 不適用於 PointPolygonLineString 資料類型。

資料分割索引鍵底下的屬性

屬性 Description
路徑 路徑陣列,可用來分割集合中的資料。 路徑不得包含萬用字元或結尾斜線。 例如,JSON 屬性 「AccountNumber」 會指定為 「/AccountNumber」。 陣列必須只包含單一值。
kind 用於資料分割的演算法。 僅支援 雜湊
{  
  "id": "testcoll",  
  "indexingPolicy": {  
    "indexingMode": "consistent",  
    "automatic": true,  
    "includedPaths": [  
      {  
        "path": "/*",  
        "indexes": [  
          {  
            "kind": "Range",  
            "dataType": "String",  
            "precision": -1  
          },  
          {  
            "kind": "Range",  
            "dataType": "Number",  
            "precision": -1  
          }  
        ]  
      }  
    ],  
    "excludedPaths": []  
  },  
  "partitionKey": {  
    "paths": [  
      "/AccountNumber"  
    ],  
    "kind": "Hash"  
  },  
  "_rid": "1tAvAP4XWww=",  
  "_ts": 1459198933,  
  "_self": "dbs/1tAvAA==/colls/1tAvAP4XWww=/",  
  "_etag": "\"00005600-0000-0000-0000-56f99bd50000\"",  
  "_docs": "docs/",  
  "_sprocs": "sprocs/",  
  "_triggers": "triggers/",  
  "_udfs": "udfs/",  
  "_conflicts": "conflicts/"  
}  
  

範例

GET https://querydemo.documents.azure.com/dbs/testdb/colls HTTP/1.1  
x-ms-offer-throughput: 1000  
x-ms-date: Mon, 28 Mar 2016 21:02:12 GMT  
authorization: type%3dmaster%26ver%3d1.0%26sig%3dP8r7%2fEZnOxv2wQr2smp4G1tCH9PkOkIZscHqsqdn6y4%3d  
Cache-Control: no-cache  
User-Agent: Microsoft.Azure.Documents.Client/1.6.0.0  
x-ms-version: 2015-12-16  
Accept: application/json  
Host: querydemo.documents.azure.com  
Content-Length: 235  
Expect: 100-continue  
  
HTTP/1.1 201 Created  
Cache-Control: no-store, no-cache  
Pragma: no-cache  
Transfer-Encoding: chunked  
Content-Type: application/json  
Server: Microsoft-HTTPAPI/2.0  
Strict-Transport-Security: max-age=31536000  
x-ms-last-state-change-utc: Mon, 28 Mar 2016 20:10:13.601 GMT  
etag: "00005600-0000-0000-0000-56f99bd50000"  
collection-partition-index: 0  
collection-service-index: 24  
x-ms-schemaversion: 1.1  
x-ms-alt-content-path: dbs/testdb  
x-ms-quorum-acked-lsn: 6  
x-ms-current-write-quorum: 3  
x-ms-current-replica-set-size: 4  
x-ms-request-charge: 4.95  
x-ms-serviceversion: version=1.6.52.5  
x-ms-activity-id: fbc3f36d-15d5-45fa-8f19-8579945451f8  
x-ms-session-token: 0:7  
Set-Cookie: x-ms-session-token#0=7; Domain=querydemo.documents.azure.com; Path=/dbs/1tAvAA==/colls/1tAvAP4XWww=  
Set-Cookie: x-ms-session-token=7; Domain=querydemo.documents.azure.com; Path=/dbs/1tAvAA==/colls/1tAvAP4XWww=  
x-ms-gatewayversion: version=1.6.52.5  
Date: Mon, 28 Mar 2016 21:02:13 GMT  
  
{  
  "id": "testcoll",  
  "indexingPolicy": {  
    "indexingMode": "consistent",  
    "automatic": true,  
    "includedPaths": [  
      {  
        "path": "/*",  
        "indexes": [  
          {  
            "kind": "Range",  
            "dataType": "String",  
            "precision": -1  
          },  
          {  
            "kind": "Range",  
            "dataType": "Number",  
            "precision": -1  
          }  
        ]  
      }  
    ],  
    "excludedPaths": []  
  },  
  "partitionKey": {  
    "paths": [  
      "/AccountNumber"  
    ],  
    "kind": "Hash"  
  },  
  "_rid": "1tAvAP4XWww=",  
  "_ts": 1459198933,  
  "_self": "dbs/1tAvAA==/colls/1tAvAP4XWww=/",  
  "_etag": "\"00005600-0000-0000-0000-56f99bd50000\"",  
  "_docs": "docs/",  
  "_sprocs": "sprocs/",  
  "_triggers": "triggers/",  
  "_udfs": "udfs/",  
  "_conflicts": "conflicts/"  
}  
  

另請參閱