英文:
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:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论