firestore rest apiを使って取得したり更新したりしたい。
初期設定
Firebase プロジェクトのウェブ API キーを使ってプロジェクトに User 作成 & idToken を取得
以下参照
https://qiita.com/Kaz-su/items/60bfd764d90537e1d424
runQuery
条件1つの場合
curl -i -X POST \
-H "Authorization:Bearer {idToken}" \
-H "Content-Type:application/json" \
-d \
'{
"structuredQuery": {
"where": {
"fieldFilter": {
"field": {
"fieldPath": "item"
},
"op": "EQUAL",
"value": {
"stringValue": "hogemi"
}
}
},
"from": [
{
"collectionId": "items"
}
]
}
}' \
'https://firestore.googleapis.com/v1/projects/{プロジェクトID}/databases/(default)/documents/:runQuery'
条件複数の場合
compositeFilterというのが必要みたい
curl -i -X POST \
-H "Authorization:Bearer {idToken}" \
-H "Content-Type:application/json" \
-d \
'{
"structuredQuery": {
"where": {
"compositeFilter": {
"op": "AND",
"filters": [
{
"fieldFilter": {
"field": {
"fieldPath": "item"
},
"op": "EQUAL",
"value": {
"stringValue": "hogemi"
},
},
},
{
"fieldFilter": {
"field": {
"fieldPath": "name"
},
"op": "EQUAL",
"value": {
"stringValue": "hogetaro"
}
}
},
{
"fieldFilter": {
"field": {
"fieldPath": "is_in"
},
"op": "EQUAL",
"value": {
"booleanValue": false
}
}
},
{
"fieldFilter": {
"field": {
"fieldPath": "flag"
},
"op": "EQUAL",
"value": {
"booleanValue": false
}
}
},
{
"fieldFilter": {
"field": {
"fieldPath": "expire"
},
"op": "GREATER_THAN",
"value": {
"timestampValue": "2021-07-14T03:49:59+00:00"
}
}
}
]
}
},
"from": [
{
"collectionId": "items"
}
],
"limit": 1
}
}' \
'https://firestore.googleapis.com/v1/projects/{プロジェクトID}/databases/(default)/documents/:runQuery'
patch
続きは明日以降書く