Can i 自动地添加索引在火库索引?
我的应用程序使请求过滤器 and refers to 火库 for 显示结果。但如果firestore无法显示结果,在控制台中我看到link to 火库 for 添加索引。所以如果我push on the link in Safari,我会看看我的firestore添加索引.
Can I 添加这个索引在应用程序的后台工作,这样我就可以继续使用该应用程序,而无需去野生动物园吗?
In the future,这样当每个error索引是自动添加.
我的意思是这个index in 火库:
And error with link示例如下:
Error download results: Error Domain=FIRFirestoreErrorDomain Code=9 "The query requires an index. You can create it here: https://console.firebase.google.com/project/*********/database/firestore/indexes?create_index=EgxQaG90b1N0dWRpb3MaEQoNcmV0cm9JbnRlcmlvchACGgkKBXByaWNlEAIaDAoIX19uYW1lX18QAg" UserInfo={NSLocalizedDescription=The query requires an index. You can create it here: https://console.firebase.google.com/project/*********/database/firestore/indexes?create_index=EgxQaG90b1N0dWRpb3MaEQoNcmV0cm9JbnRlcmlvchACGgkKBXByaWNlEAIaDAoIX19uYW1lX18QAg}
我使用的代码:
fileprivate func observeQuery() {
guard let query = query else { return }
stopObserving()
setLoadingScreen()
listener = query.addSnapshotListener { [unowned self] (snapshot, error) in
if let snapshot = snapshot {
DispatchQueue.main.asyncAfter(deadline: time) {
let hallModels = snapshot.documents.map { (document) -> Halls in
if let hallModel = Halls(dictionary: document.data()) {
return hallModel
} else {
fatalError("Error!")
}
}
self.halls = hallModels
self.document = snapshot.documents
self.removeLoadingScreen()
self.tableView.reloadData()
}
} else {
// firestore can't display result and i get an error with link
print("Error download results: \(error!)")
self.tableView.separatorStyle = .none
self.tableView.reloadData()
}
}
}
在这一行中我收到错误。我认为如果可能的话,在这一行中需要编写代码,但我不知道该怎么做。:(
} else {
// firestore can't display result and i get error with link
print("Error download results: \(error!)")
self.tableView.separatorStyle = .none
self.tableView.reloadData()
}
然后我添加索引 in 火库我不再得到链接错误.
有一种方法可以使用 CLI 自动化索引部署(可能在 CI/CD 中或事先,以便他们有机会在部署需要它们的应用程序版本之前对所有文档建立索引)。
当您在项目中初始化 firestore 时(即firebase init firestore
) a firestore.indexes.json
将创建文件。在那里,您可以添加所有复合索引并使用以下命令部署它们:firebase deploy --only firestore:indexes
.
这是文档的链接:https://firebase.google.com/docs/firestore/query-data/indexing https://firebase.google.com/docs/firestore/query-data/indexing
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)