Firestore查询需要索引的种类是什么?

huangapple go评论108阅读模式
英文:

Which kind of firestore queries require indexes?

问题

因为通常第一次运行带有条件的Firestore查询时,我通常需要为我添加条件的字段添加索引,所以有点困惑,但这次没有要求,这不是真正的问题,但关于Firestore查询/索引工作原理,我可能有什么不理解的?

  const q = query(
    collection(db, 'activityDetails'),
    where('activityId', '==', activityId),
  );

我会假设由于activityId不是自动的主索引,我需要将其添加为索引,而Firestore通常会为您提供一个链接来创建索引,对吗?

英文:

Was a bit confused because usually the first time I run a Firestore query with a condition I'm usually required to add an index for the field I'm adding a condition for but this time it didn't, its not really an issue but what am I not understanding about how Firestore queries/indexing works?

  const q = query(
    collection(db, 'activityDetails'),
    where('activityId', '==', activityId),
  );

I'd assume that since activityId isn't the automatic primary index I'd be required to add it as an index and Firestore usually spits out a link for you to create the index?

答案1

得分: 2

当您调用.where('activityId', '==', activityId)而没有添加任何排序时,就无需显式创建索引。像这样的最基本查询所需的索引会自动为您创建。请参阅下面的文档:

英文:

When you're calling .where('activityId', '==', activityId) without adding any kind of order, then there is no need to explicitly create an index. The indexes required for the most basic queries like this one, are automatically created for you. Please see below the docs:

huangapple
  • 本文由 发表于 2023年8月10日 17:19:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76874317.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定