gpt4 book ai didi

firebase - 我是否正确使用Firestore索引?

转载 作者:行者123 更新时间:2023-12-03 04:18:11 25 4
gpt4 key购买 nike

我最近一直在使用Flutter和Firebase构建一些类似于LinkedIn的网络应用程序。该应用程序的功能之一是能够根据您所在的位置和工作类型等因素将您的个人资料与数据库中注册的其他用户进行匹配。为此,我一直在使用带有某些条件的Firestore快照。其中两个条件要求Firebase按“上次 Activity ”对用户进行排序,并且仅读取过去一个月内登录的用户的文档。为了整理结果并减少一次请求的文档读取数量。这是我正在使用的Firebase快照的一个示例:

Firestore.instance
.collection('usersIsb')
.where('Set', isEqualTo: true)
.where('Account Type', isEqualTo: _tempType)
.where('Services List', arrayContainsAny: _tempServices)
.where('Location', isEqualTo: widget.userData.location)
.where('Last Active', isGreaterThanOrEqualTo: widget.dateLimit)
.orderBy('Last Active', descending: true)
.limit(10)
.snapshots()
自然,由于请求的复杂性,Firebase要求我为其创建索引,所以我做到了,并且一切似乎都正常运行,而没有任何明显的速度下降或问题。但是,我有几个问题要回答:
  • 这些索引是实时的吗?是否在每次创建新用户文档时更新?
  • 一个Firestore数据库中可以有多少个索引?索引过程听起来很费力,所以我假设存在缺点。
  • 首先应该这样做吗?感觉好像我做错了...

  • 额外: These are the Indexes I currently have enabled in my Firestore database
    这是我在平台上的第一篇文章,因此如有需要,可以随时询问更多信息,也欢迎您提供有关如何更有效地实现目标的建议。

    最佳答案

    Are these indexes real-time? As in updated every time a new user document is created?



    How many Indexes can I have in one Firestore database?


    documentation on index limits说:

    Maximum number of composite indexes for a database: 200


    Maximum number of single-field index exemptions for a database: 200


    您应该通读那里的整个文档以了解所有限制。

    Is this how it's supposed to be done in the first place?


    这是一个见解的问题。您可以在记录的限制范围内做任何您想做的事情。如果您的索引和查询适用于您的用例,那很好。

    关于firebase - 我是否正确使用Firestore索引?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64234677/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com