0
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のGeoFireStoreで任意の値をwhereで絞るクエリでハマった件

Last updated at Posted at 2020-03-20

GeoFireStoreのMap型をwhereで絞るクエリで躓いたので、メモ。(30分くらいハマった)

やりたかったこと

GeoFireStoreで、別途保持している任意の値をwhereで絞り込みたい。
https://geofirestore.com/index.html

geofirestore.ts
interface GeoDocument {
    g: string;
    l: GeoPoint;
    d: DocumentData;
  }

上記のような型指定されており、下記のようにdの中に任意の値を入れられます。この時dはマップ型。

sample = {
    ...
    d: { 
       id : 'hogehoge',
       coordinates: [35......° N, 139...° E]
    };
  }

なので、firestore公式サンプルに乗っているマップ型の場合を参考にwhere句で絞り込む

  const geofirestore: GeoFirestore = new GeoFirestore(firestore);
  const geocollection: GeoCollectionReference = geofirestore.collection('geo');
  const ref = geocollection.where("d.id", '==', id).get();

これだとなぜか取れない。
ちなみに通常のマップ型は以下のようにクエリを書くことで解決します。

 const ref = fireStore.collection('doc').where('test.is_map','==',true).get();

解決方法=> dは記入せず、直接マップ以下のキー名で絞り込む。

  const geofirestore: GeoFirestore = new GeoFirestore(firestore);
  const geocollection: GeoCollectionReference = geofirestore.collection('geo');
  const ref = geocollection.where("id", '==', id).get();

理由がイマイチピンときていないのですが、とりあえずハマったのでメモ..

0
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
0
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?