[英]How to filter Firebase Firestore Array data in React native app?
[英]How to user filter with Firestore database in React Native?
我想过滤 firestore 查询以获取所有不包含特定值的文档。
我使用@react-native-firebase
import firestore from '@react-native-firebase/firestore';
const getUnreadDocs = async () => {
const unreadDocs = await firestore()
.collection('rooms')
.doc('aDRKtxbhG9g5IfbKcsa4')
.collection('messages')
.where('seen', 'not-in', ['7B6jaZngXeN7V4r3eRoDBdlcj6m2'])
.get();
console.log(`unreadDocs`, unreadDocs);
};
文档从查询返回
数据是如何存储的?
我们有收藏
rooms Collection -> Docs -> fields
|
V
messages Collection -> Docs -> fields
查询应该返回什么? 正如我们在查询中提到的,文档不应在seen
字段中包含7B6jaZngXeN7V4r3eRoDBdlcj6m2
所以,查询应该只返回一个文档,即
in
/ not-in
运算符检查当前单值字段是否具有您指定的值列表中存在/不存在的值。 但是您seen
的字段是一个数组,不适用于此运算符。
相反,您需要对其使用array-contains
来检查值是否存在。 没有等效array-does-not-contain
运算符来检查数组字段中是否不存在值。
另见:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.