![](/img/trans.png)
[英]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.