![](/img/trans.png)
[英]Flutter post request headers do not appear on Google Cloud Function
[英]Firestore REST API, POST request succeeds, document does not appear in emulator UI, and cloud triggers do not fire
自上周以來,我一直在使用 Firestore 遇到問題。
問題:未從 REST API 寫入 Firestore 數據庫。
發布示例:
curl --request POST \
'http://127.0.0.1:8080/v1/projects/demo-<PROJECT_ID>/databases/(default)/documents/HOME?documentId=11223344&key=<API_KEY>' \
--header 'Authorization: Bearer <TOKEN>' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{ "fields":{ "my_field":{ "stringValue":"random" }} }' \
--compressed
**注意:PROJECT_ID、API_KEY 和 TOKEN 具有正確的值,我只是為這篇文章刪除了它們。
Firestore 規則和 index.js 下面的任何幫助將不勝感激!
rules_version = '2';
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write: if true
}
}
}
const functions = require( "firebase-functions" );
exports.userPath = functions
.firestore.document( "{root}/{node}" )
.onCreate( async( snap, context ) => {
try
{
console.log( "Document @ path: "+snap.ref.path );
await sleep( 250 );
await snap.ref.delete();
return console.log( "Document deleted @ path: "+snap.ref.path );
}
catch( error )
{ return await console.log( "FATAL error" ); }
});
Cloud Firestore 模擬器嘗試忠實地復制生產服務的行為,但有一些明顯的限制,例如在事務方面,例如,當您測試涉及多個並發寫入一個文檔的功能時,模擬器在某些情況下完成寫入請求可能會很慢在這種情況下,鎖可能需要 30 秒才能釋放。 如果需要,建議考慮相應地調整測試超時。
在典型的生命周期中,Cloud Firestore function 執行以下操作:
您可能需要檢查並確認文檔路徑不得包含尾部斜杠。
您共享的代碼使用 onCreate 方法,該方法僅響應文檔創建。對於指向不存在文檔的 DocumentSnapshot,任何數據訪問都將返回“未定義”。 您可以使用exists屬性來顯式驗證文檔的存在。
對不存在的文檔的刪除被視為成功(除非提供了 lastUptimeTime)。
(snapshot: QueryDocumentSnapshot, context: EventContext) => any)
: CloudFunction<QueryDocumentSnapshot>
請查看有用的文檔以獲取有關能夠測試跨產品交互和Firestore DocumentSnapshot使用的模擬器的更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.