Method: projects.databases.documents.runQuery

執行查詢。

HTTP 要求

POST https://firestore.googleapis.com/v1beta1/{parent=projects/*/databases/*/documents}:runQuery

這個網址使用 gRPC 轉碼語法。

路徑參數

參數
parent

string

執行個體類型,父項資源名稱。格式:projects/{projectId}/databases/{databaseId}/documentsprojects/{projectId}/databases/{databaseId}/documents/{document_path}。例如 projects/my-project/databases/my-database/documentsprojects/my-project/databases/my-database/documents/chatrooms/my-chatroom

要求主體

要求主體包含下列結構的資料:

JSON 表示法
{
  "explainOptions": {
    object (ExplainOptions)
  },

  // Union field query_type can be only one of the following:
  "structuredQuery": {
    object (StructuredQuery)
  }
  // End of list of possible types for union field query_type.

  // Union field consistency_selector can be only one of the following:
  "transaction": string,
  "newTransaction": {
    object (TransactionOptions)
  },
  "readTime": string
  // End of list of possible types for union field consistency_selector.
}
欄位
explainOptions

object (ExplainOptions)

選用設定。說明查詢的選項。設定後,系統就會傳回其他查詢統計資料。否則,系統只會傳回查詢結果。

聯集欄位 query_type。要執行的查詢。query_type 只能採用下列其中一種設定:
structuredQuery

object (StructuredQuery)

結構化查詢。

聯集欄位 consistency_selector。這筆交易的一致性模式。如果未設定,則會預設為同步一致性。consistency_selector 只能採用下列其中一種設定:
transaction

string (bytes format)

在有效交易內執行查詢。

此處的值是執行查詢的不透明交易 ID。

Base64 編碼的字串。

newTransaction

object (TransactionOptions)

開始新的交易並讀取文件。預設為唯讀交易。系統會傳回新的交易 ID,做為串流中的第一個回應。

readTime

string (Timestamp format)

讀取特定時間的文件。

這個時間戳記須為過去 1 小時內的微秒精確度,或者如果已啟用時間點復原,也可以是過去 7 天內的整分鐘時間戳記。

RFC3339 世界標準時間「Zulu」格式的時間戳記,解析度以奈秒為單位,小數點後最多 9 位。範例:"2014-10-02T15:01:23Z""2014-10-02T15:01:23.045123456Z"

回應主體

Firestore.RunQuery 的回應。

如果執行成功,回應主體中會有結構如下的資料:

JSON 表示法
{
  "transaction": string,
  "document": {
    object (Document)
  },
  "readTime": string,
  "skippedResults": integer,
  "explainMetrics": {
    object (ExplainMetrics)
  },

  // Union field continuation_selector can be only one of the following:
  "done": boolean
  // End of list of possible types for union field continuation_selector.
}
欄位
transaction

string (bytes format)

隨此要求所啟動的交易。只能在第一個回應中設定,且必須在要求中設定 RunQueryRequest.new_transaction。如已設定,則此回應中不會設定其他欄位。

Base64 編碼的字串。

document

object (Document)

回報部分進度時未設定查詢結果。

readTime

string (Timestamp format)

讀取文件的時間。這可能是單調遞增;在這種情況下,結果串流中的舊有文件在 readTime 和此檔案之間無法保證不會有任何改變。

如果查詢未傳回任何結果,系統就不會傳送包含 readTime 的回應,不會傳送任何 document,而是代表查詢的執行時間。

RFC3339 世界標準時間「Zulu」格式的時間戳記,解析度以奈秒為單位,小數點後最多 9 位。範例:"2014-10-02T15:01:23Z""2014-10-02T15:01:23.045123456Z"

skippedResults

integer

因上一個回應與目前回應之間的偏移,而略過的結果數。

explainMetrics

object (ExplainMetrics)

查詢說明指標。只有在提供 RunQueryRequest.explain_options 時才會顯示,且只會與串流中的最後一個回應一起傳送一次。

聯集欄位 continuation_selector。查詢的接續模式。如果存在,表示目前的查詢回應串流已完成。您可以設定是否要包含 document,但設定後就不會傳回其他結果。continuation_selector 只能採用下列其中一種設定:
done

boolean

如果存在,Firestore 已完成要求,就不會再傳回其他文件。

授權範圍

需要下列其中一種 OAuth 範圍:

  • https://www.googleapis.com/auth/datastore
  • https://www.googleapis.com/auth/cloud-platform

詳情請參閱驗證總覽