# function.regionの使い方(Firebase) ## function.regionとは Firebaseのリージョンを設定するコマンド.デフォルトだとus-central(アイオワ州)が設定されている. リージョンを設定できる場所は[このサイト](https://firebase.google.com/docs/functions/locations?hl=ja)を参照. リージョンは,アプリのレスポンスに直結するため,1つのリージョンのみを使用する場合は,最もユーザが多い地域に近いリージョンを選ぶのがセオリー. しかし,データ転送料なども考慮することが大切. [/abmp/firebase/functions/src/firestore/utils/firestoreToAlgolia.ts](https://github.com/R-D-Inc/abmp/pull/55/files) ``` export const onCreated = ({ collectionName, region = REGION.ASIA_NORTHEAST1, algoliaIndexName }: CommonArgs) => functions .region(region) .firestore.document(`${collectionName}/{id}`) .onCreate((snap, context) => { const client = getClient() const index = client.initIndex(algoliaIndexName) const obj = snap.data() obj.objectID = context.params.id obj.id = context.params.id return index.saveObject(obj) }) ``` ## 補足 [トリガー](https://firebase.google.com/docs/functions/firestore-events?hl=ja)(OnCreateなど) [参考サイト](https://qiita.com/qrusadorz/items/99432fac6cbc93ebaff2)