Javascript 如何限制使用多个筛选器查询的Firebase复合索引的数量
我正在创建一个Firestore项目,其中包含群聊/论坛,用户可以根据以下字段筛选帖子:Javascript 如何限制使用多个筛选器查询的Firebase复合索引的数量,javascript,firebase,vue.js,google-cloud-firestore,Javascript,Firebase,Vue.js,Google Cloud Firestore,我正在创建一个Firestore项目,其中包含群聊/论坛,用户可以根据以下字段筛选帖子: 喜欢的人数 如果帖子包含附件(照片和/或文件) 4个标签(问题、考试、作业、笔记) 用户可以同时应用任何或所有这些过滤器 每个Post文档都有以下字段: 剪辑数 每个标记使用不同的布尔值 帖子中的文件列表 文章的正文 我创建这些查询的方法如下所示: setQueryFilters() { var queryPosts = db.collection('posts').where('cou
- 喜欢的人数
- 如果帖子包含附件(照片和/或文件)
- 4个标签(问题、考试、作业、笔记)
setQueryFilters() {
var queryPosts = db.collection('posts').where('course_id', '==', this.course);
if (this.filterByNotes) {
queryPosts = queryPosts.where('notesTag', '==', true);
}
if (this.filterByExams) {
queryPosts = queryPosts.where('examsTag', '==', true);
}
if (this.filterByAssignments) {
queryPosts = queryPosts.where('assignmentsTag', '==', true);
}
if (this.filterByQuestions) {
queryPosts = queryPosts.where('questionsTag', '==', true);
}
if (this.filterByFiles) {
queryPosts = queryPosts.where('files', '!=', []);
}
if (this.filterByClips) {
queryPosts = queryPosts.orderBy('clips', 'desc');
} else {
queryPosts = queryPosts.orderBy('created_at', 'desc');
}
return queryPosts;
},
由于可以应用6个不同的过滤器,我有数百个可能的不同查询,所有这些查询(除了少数)都需要我在firebase中创建复合索引。我甚至不确定firebase是否允许我创建这么多索引。有更好的方法吗?Firebase CLI允许您基于项目工作区中的JSON文件部署安全规则和索引。您可以编写代码来生成描述要创建的索引的JSON,然后使用CLI中的一个命令部署它们。创建所有必需的索引应该不会有任何问题 另见: