取得文件
Azure Cosmos DB 是全域散發的多模型資料庫,並可支援多個 API。 本文涵蓋適用於 Azure Cosmos DB 的 SQL API。
作業會 Get Document
依檔分割索引鍵和檔索引鍵擷取檔。
要求
方法 | 要求 URI | 描述 |
---|---|---|
GET | HTTPs://{databaseaccount}.documents.azure.com/dbs/{db-id}/colls/{coll-id}/docs/{doc-id} | 請注意,{databaseaccount} 是您訂用帳戶下建立的 Azure Cosmos DB 帳戶名稱。 {db-id} 值是使用者產生的資料庫名稱/識別碼,而不是系統產生的識別碼 (rid) 。 {coll-id} 值是集合的名稱。 {doc-id} 值是要擷取的檔識別碼。 |
標題
如需所有 Cosmos DB 要求所使用的標頭,請參閱常見的 Azure Cosmos DB REST 要求標頭 。 讀取檔的重要回應標頭如下所示:
標頭 | 必要 | 類型 | Description |
---|---|---|---|
If-None-Match | 選用 | String | 此值應該是資源的 etag。 讓作業有條件,也就是說,回應只包含資料庫中的值與標頭中指定的值不同。 |
x-ms-documentdb-partitionkey | 選擇性 | Array | 要讀取之檔的分割區索引鍵值。 只有在使用 partitionKey 定義建立集合時,才必須包含 。 |
x-ms-consistency-level | 選用 | String | 這是一致性層級覆寫。 有效值為: 強式、 限定、 會話或 最終 (,以最強到最弱) 。 覆寫必須與帳戶設定的一致性層級相同或較弱。 |
x-ms-session-token | 選用 | String | 搭配工作階段層級一致性使用的字串權杖。 用戶端必須在會話一致性的讀取要求期間回應此標頭的最新讀取值。 |
主體
無。
回應
傳回所要求檔的內容。
標題
如需所有 Azure Cosmos DB 回應所傳回的標頭,請參閱 常見的 Azure Cosmos DB REST 回應標頭 。 取得檔的重要回應標頭如下所示:
標頭 | 類型 | Description |
---|---|---|
x-ms-request-charge | 數字 | 作業所耗用的要求單位數目。 |
狀態碼
下表列出此作業所傳回的常見狀態碼。 如需狀態碼的完整清單,請參閱HTTP 狀態碼。
HTTP 狀態碼 | Description |
---|---|
200 確定 | 作業成功。 |
304 未修改 | 要求的檔未修改,因為 If-Match 標頭中指定的 eTag 值。 服務傳回空白回應本文。 |
400 不正確的要求 | x-ms-consistency-level標頭中設定的覆寫比建立帳戶期間設定的覆寫強。 例如,如果一致性層級是 會話,覆寫不能是 強 式或 系結。 |
404 找不到 | 文件不再是資源,也就是說已刪除文件。 |
主體
屬性 | 描述 |
---|---|
id | 這是用來識別檔的唯一名稱,也就是說,沒有兩份檔可以共用相同的 識別碼。 識別碼 不能超過 255 個字元。 |
自訂 | 任何使用者定義的 JSON。 |
_擺脫 | 它是 系統產生的屬性。 資源識別碼 (_rid) 是資源模型上每個資源堆疊的階層式唯一識別碼。 它是在內部用來放置和導覽文件資源。 |
_Ts | 它是系統產生的屬性。 代表資源的上次更新時間戳記。 此值在 Unix 時間中。 |
_自我 | 它是系統產生的屬性。 代表資源的唯一可定址 URI。 |
_Etag | 它是系統產生的屬性,指定開放式並行控制所需的資源 etag。 |
attachments | 它是系統產生的屬性,指定附件資源的可定址路徑。 |
{
"id": "SalesOrder1",
"ponumber": "PO18009186470",
"OrderDate": "2005-07-01T00:00:00",
"ShippedDate": "0001-01-01T00:00:00",
"AccountNumber": "Account1",
"SubTotal": 419.4589,
"TaxAmount": 12.5838,
"Freight": 472.3108,
"TotalDue": 985.018,
"Items": [
{
"OrderQty": 1,
"ProductId": 760,
"UnitPrice": 419.4589,
"LineTotal": 419.4589
}
],
"_rid": "d9RzAJRFKgwBAAAAAAAAAA==",
"_self": "dbs/d9RzAA==/colls/d9RzAJRFKgw=/docs/d9RzAJRFKgwBAAAAAAAAAA==/",
"_etag": "\"0000d986-0000-0000-0000-56f9e25b0000\"",
"_ts": 1459216987,
"_attachments": "attachments/"
}
範例
GET https://querydemo.documents.azure.com/dbs/testdb/colls/testcoll/docs/SalesOrder1 HTTP/1.1
x-ms-documentdb-partitionkey: ["Account1"]
x-ms-date: Tue, 29 Mar 2016 02:03:06 GMT
authorization: type%3dmaster%26ver%3d1.0%26sig%3dyhmbeaUDy6NCOyWr0t7Cxx4aMT4Yx%2bJnRAs%2br8Theyw%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
Cookie: x-ms-session-token#0=772; x-ms-session-token=772
HTTP/1.1 200 Ok
Cache-Control: no-store, no-cache
Pragma: no-cache
Transfer-Encoding: chunked
Content-Type: application/json
Content-Location: https://querydemo.documents.azure.com/dbs/testdb/colls/testcoll/docs/SalesOrder1
Server: Microsoft-HTTPAPI/2.0
Strict-Transport-Security: max-age=31536000
x-ms-last-state-change-utc: Mon, 28 Mar 2016 14:47:03.949 GMT
etag: "0000d986-0000-0000-0000-56f9e25b0000"
x-ms-resource-quota: documentSize=10240;documentsSize=10485760;collectionSize=10485760;
x-ms-resource-usage: documentSize=0;documentsSize=2;collectionSize=2;
x-ms-schemaversion: 1.1
x-ms-alt-content-path: dbs/testdb/colls/testcoll
x-ms-content-path: d9RzAJRFKgw=
x-ms-request-charge: 1
x-ms-serviceversion: version=1.6.52.5
x-ms-activity-id: c22bc349-2c02-4b80-81b9-a2d758c92902
x-ms-session-token: 0:772
Set-Cookie: x-ms-session-token#0=772; Domain=querydemo.documents.azure.com; Path=/dbs/testdb/colls/testcoll
Set-Cookie: x-ms-session-token=772; Domain=querydemo.documents.azure.com; Path=/dbs/testdb/colls/testcoll
x-ms-gatewayversion: version=1.6.52.5
Date: Tue, 29 Mar 2016 02:03:06 GMT
{
"id": "SalesOrder1",
"ponumber": "PO18009186470",
"OrderDate": "2005-07-01T00:00:00",
"ShippedDate": "0001-01-01T00:00:00",
"AccountNumber": "Account1",
"SubTotal": 419.4589,
"TaxAmount": 12.5838,
"Freight": 472.3108,
"TotalDue": 985.018,
"Items": [
{
"OrderQty": 1,
"ProductId": 760,
"UnitPrice": 419.4589,
"LineTotal": 419.4589
}
],
"_rid": "d9RzAJRFKgwBAAAAAAAAAA==",
"_self": "dbs/d9RzAA==/colls/d9RzAJRFKgw=/docs/d9RzAJRFKgwBAAAAAAAAAA==/",
"_etag": "\"0000d986-0000-0000-0000-56f9e25b0000\"",
"_ts": 1459216987,
"_attachments": "attachments/"
}