我正在嘗試使用游標和“startAt”將 REST 請求分頁到 Firestore。根據Paginate-documentation,游標應該等于上一個查詢的最后一個檔案。由于REST 檔案沒有示例,我嘗試通過在 startAt 物件中插入整個檔案作為游標來運行它;像這樣:
POST https://firestore.googleapis.com/v1/PROJECT-NAME/databases/(default)/documents/organizations/testManyInstructions:runQuery
{
"structuredQuery": {
"from": [
{
"collectionId": "instructions"
}
],
"where": {
"fieldFilter": {
"field": {
"fieldPath": "belongsToDepartementID"
},
"op": "EQUAL",
"value": {
"stringValue": "toplevel-document-id"
}
}
},
"orderBy": [
{
"field": {
"fieldPath": "instructionNumber"
},
"direction": "ASCENDING"
}
],
"startAt": {
"values": [{
"document": {
"name": "projects/PROJECT-NAME/databases/(default)/documents/organizations/testManyInstructions/instructions/i0",
"fields": {
"checkbox": {
"booleanValue": false
},
"retrainTimespanDays": {
"integerValue": "365000"
},
"approvedByName": {
"stringValue": ""
},
"instructionNumber": {
"stringValue": "instr. 0"
},
"instructionCurrentRevision": {
"stringValue": "A"
},
"instructionCurrentRevisionPublishingDate": {
"timestampValue": "1999-01-01T00:00:00Z"
},
"instructionFileURL": {
"stringValue": ""
},
"instructionTitle": {
"stringValue": "dummy Title0"
},
"instructionFileUploadDate": {
"timestampValue": "1999-01-01T00:00:00Z"
},
"belongsToDepartementID": {
"stringValue": "toplevel-document-id"
},
"approvedByEmailAdress": {
"stringValue": ""
}
},
"createTime": "2022-02-18T13:55:42.807103Z",
"updateTime": "2022-02-18T13:55:42.807103Z"
}
}
]
},
"limit": 5
}
}
- 如果沒有“startAt”-Object,以下代碼可以正常作業并回傳 5 個檔案。
- 使用“startAt”-Object,將回傳此錯誤:
{
"error": {
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"document\" at 'structured_query.start_at.values[0]': Cannot find field.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "structured_query.start_at.values[0]",
"description": "Invalid JSON payload received. Unknown name \"document\" at 'structured_query.start_at.values[0]': Cannot find field."
}
]
}
]
}
}
]
請告知,如何正確設定 startAt 物件中的游標。
uj5u.com熱心網友回復:
我使用偏移量而不是 startAt 運行了一個類似的查詢,所以我嘗試修改并讓它作業。這是我使用的其余 api 檔案。startAt 需要一個 Cursor 物件,它是一個值陣列。 https://firebase.google.com/docs/firestore/reference/rest/v1/StructuredQuery https://firebase.google.com/docs/firestore/reference/rest/v1/Cursor https://firebase.google。 com/docs/firestore/reference/rest/Shared.Types/ArrayValue#Value
我也希望有一個例子!
"startAt": {
"values": [{
"stringValue": "Cr"
}]
},
"orderBy": [{
"field": {
"fieldPath": "Summary"
}
}],
祝你好運!
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/431778.html
