[英]How to filter out certain documents in a firestore query
我希望在我的社交應用中實現朋友搜索功能。 為此,我嘗試在數據庫的users
集合中查詢每個用戶的文檔,但它應該排除某些特定文檔,例如當前用戶已經是朋友或請求待處理的用戶。
是否可以通過在 Firestore 中傳遞這些文檔引用 ID 來查詢所有用戶文檔,不包括特定文檔。
如果沒有,有人可以說一種構建數據的方法,以便我可以實現此功能。 謝謝。
您可以使用not-in
查詢。 這是一個簡單的例子(取自文檔):
citiesRef.where('country', 'not-in', ['USA', 'Japan']);
既然要通過ID查詢,可以使用firebase.firestore.FieldPath.documentId()
作為字段名( source )
citiesRef.where(firebase.firestore.FieldPath.documentId(), 'not-in', ['123', '456']);
或者,您可以嘗試使用'__name__'
字段名稱( source ):
citiesRef.where('__name__', 'not-in', ['123', '456']);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.