【发布时间】:2020-01-29 21:37:29
【问题描述】:
我有一个名为“用户”的 Firestore 集合。 这是我有兴趣执行的三个 DB 读取:
1:
const onNewestChange = (dispatch) => {
firebase
.firestore()
.collection('users')
.where('role', '==', 'a')
.where('active', '==', true)
.orderBy('createdAt')
.limit(10)
.onSnapshot((querySnapshot) => {
const newestProfiles = querySnapshot.forEach((queryDocSnapshot) => {
const profile = queryDocSnapshot.data();
newestProfiles.push(profile);
});
dispatch({ type: types.LOAD_NEWEST, payload: newestProfiles });
});
};
2:
const onMostPopularChange = (dispatch) => {
firebase
.firestore()
.collection('users')
.where('role', '==', 'a')
.where('active', '==', true)
.orderBy('lifetimeInbox')
.limit(10)
.onSnapshot((querySnapshot) => {
const popularProfiles = querySnapshot.forEach((queryDocSnapshot) => {
const profile = queryDocSnapshot.data();
popularProfiles.push(profile);
});
dispatch({ type: types.LOAD_POPULAR, payload: popularProfiles });
});
};
3:
const onMostActiveChange = (dispatch) => {
firebase
.firestore()
.collection('users')
.where('role', '==', 'a')
.where('active', '==', true)
.orderBy('lifetimeRead')
.limit(10)
.onSnapshot((querySnapshot) => {
const activeProfiles = querySnapshot.forEach((queryDocSnapshot) => {
const profile = queryDocSnapshot.data();
activeProfiles.push(profile);
});
dispatch({ type: types.LOAD_ACTIVE, payload: activeProfiles });
});
};
示例“用户”文档具有以下字段:
- 用户名
- 法定姓名
- 角色
- 活跃
- 创建于
- lifetimeInbox
- lifetimeRead
我创建了以下复合索引:
也试过了:
我的问题是我试图解决的初始错误即使在创建复合索引后仍然存在
错误:Firestore:操作被拒绝,因为系统未处于操作执行所需的状态。 (firestore/failed-precondition)
可以做些什么来解决这个问题?
【问题讨论】:
标签: javascript firebase google-cloud-firestore