firebase-返回多个查询作为collectionData?
/a>运算符时,当平等数为10或更少时。当它大于10时,我将把数组分为多个长度10的子阵列,并初始化多个查询请求。
当长度小于10时,我只是将 Q
用作查询请求,返回返回collectionData(q,{idfield:'id''});
。但是,当我拥有 Q0
, Q1
等时,我不知道如何以相同的方式返回它们,就像返回 Q
。
问题是如何返回 Q0
, Q1
,...使用与仅返回 q
的相同语法?
constructor(private firestore: Firestore) {
}
getUserChats() {
const userId = '12345678910';
const userRef = doc(this.firestore, `users/${userId}`);
return docData(userRef).pipe(
switchMap((data) => {
let userChats = data.chats;
let chatsRef = collection(this.firestore, 'chats');
if (userChats.length <= 10) {
//use the query normally as the 'in' operator has a limit of 10
let q = query(chatsRef, where(documentId(), 'in', userChats));
return collectionData(q, { idField: 'id' });
} else {
//breakdown the userChats array into sub-arrays of length 10
//it is hardcoded for proof-of-concept
let q0 = query(chatsRef, where(documentId(), 'in', userChats.slice(0, 10)));
let q1 = query(chatsRef, where(documentId(), 'in', userChats.slice(10, 20)));
//...
//how to combine q0 and q1?
return collectionData(????????????????, { idField: 'id' });
}
})
);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我提出的解决方案:
10
(最后一个段可能具有10
或更少),在
每个片段的操作员中,其中最多包含10
平等性,collection> collectiondata
然后用于每个查询中的每个查询返回可观察的combineLatest
从rxjs中使用,然后与可观察到的数组一起使用,然后返回以测试功能,确保检查检查功能
null
案例,因为这将引发一个例外:Here is the solution I have come up with:
10
(the last segment might have10
or less)in
operator for each segment, which contains at most10
equalitiescollectionData
is then used for each query in the array, which returns an observablecombineLatest
from RxJS is then used with the array of observables and it then returnedTo test the function, ensure to check for the
null
case, as this will thrown an exception: