未捕获(承诺中)错误:查询需要索引 [英] Uncaught (in promise) Error: The query requires an index
问题描述
一旦添加了Where方法,我就会收到此错误,但是如果没有Where子句,它就可以工作.在集合中,每个文档都具有一个称为状态"的布尔值.
I get this error once I added the Where method, but it works without the Where clause. In collection every document has Boolean called "status".
db.firestore().collection('jobs').where("status","==",true).orderBy("createDate").limit(10).get().then(querySnapshot =>{
})
})
感谢所有帮助.谢谢!
推荐答案
由于您要查询两个字段( status
和 createDate
),因此需要一个这两个字段的综合索引.会自动创建各个字段上的索引,但仅在您要求时才创建复合索引.
Since you're querying on two fields (status
and createDate
), there needs to be a composite index on those two fields. Indices on individual fields are automatically created, but composite indexes are only created when you ask for them.
错误消息应包含直接指向控制台的链接以完成该任务.如果不是这种情况,您可以在此处创建.
The error message should contain a link directly to the console to complete that task. If that's not the case, you can create it here.
这篇关于未捕获(承诺中)错误:查询需要索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!