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 1 year has passed since last update.

Firestoreをmapフィールドに存在する値で検索する

Posted at

こんにちわ、CROSSER開発者です:relaxed:
今回はFirestoreにあるmapフィールドにある値で検索する方法を共有したいと思います:fist:
どなたかの参考になれば嬉しいです:sparkles:

Firestore Documentの例

例えばこんなドキュメントがあり、userAが2021/11/13よりも前のデータがあるmapのドキュメントのみを取得したい時にこの記事は参考になると思います。

user / user1 / like{'userA':2021/11/12, 'userB':2021/11/13,'userC':2022/1/1}
user / user2 / like{'userA':2022/1/2}

やり方

admin.firestore().collection('user').where('like.userA', <=, 2021/11/12(Timestamp型)).get();

これでuser1のドキュメントが取得できます:grin:

補足

userAを可変にしたい時はこれでいけます:muscle:

admin.firestore().collection('user').where(`like.${userName}`, <=, 2021/11/12(Timestamp型)).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?