2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

firestore rest apiで取得更新

Posted at

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

続きは明日以降書く

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?