简体   繁体   English

如何在 Firestore 查询中过滤掉某些文档

[英]How to filter out certain documents in a firestore query

I'm looking to implement a friends search function in my social app.我希望在我的社交应用中实现朋友搜索功能。 For this I try to query for every user's document in the users collection of the DB, but it should exclude some specific documents like users who the current user is already friends with or request pending.为此,我尝试在数据库的users集合中查询每个用户的文档,但它应该排除某些特定文档,例如当前用户已经是朋友或请求待处理的用户。

Is it possible to query for all the users documents, excluding specific documents by passing those documents reference ID's in Firestore.是否可以通过在 Firestore 中传递这些文档引用 ID 来查询所有用户文档,不包括特定文档。

If not, can somebody say a way to structure the data so that I can implement this functionality.如果没有,有人可以说一种构建数据的方法,以便我可以实现此功能。 Thanks.谢谢。

You can use the not-in query.您可以使用not-in查询。 Here would be a simple example (taken from the docs):这是一个简单的例子(取自文档):

citiesRef.where('country', 'not-in', ['USA', 'Japan']);

Since you want to query by the ID, you can use firebase.firestore.FieldPath.documentId() as the field name ( source )既然要通过ID查询,可以使用firebase.firestore.FieldPath.documentId()作为字段名( source )

citiesRef.where(firebase.firestore.FieldPath.documentId(), 'not-in', ['123', '456']);

Alternatively you might try to use the '__name__' field-name ( source ):或者,您可以尝试使用'__name__'字段名称( source ):

citiesRef.where('__name__', 'not-in', ['123', '456']);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Firestore:如何通过存在于其他集合中来过滤文档? - Firestore: how to filter documents by existing in other collection? 某些文档的 firestore 快照 - firestore snapshot of certain documents 如何在 Cloud Firestore 查询中加入多个文档? - How to join multiple documents in a Cloud Firestore query? 如何 select 文档在 Firestore 子集合中超过某个日期? - How to select documents in a firestore subcollection that are past a certain date? ElasticSearch查询过滤掉某些相机 - ElasticSearch Query to filter out certain cameras React 和 FireStore - 如何找出集合中的文档总数 - React and FireStore - How to find out the total number of documents in a collection 如何阻止 firestore web 客户端根据文档内容阅读规则中的某些文档? - How do I stop a firestore web client from reading certain documents in rules based off a documents content? 如何使用JavaScript有条件地将过滤器应用于Firestore查询 - How to conditionally apply a filter to a Firestore query with JavaScript 如何使用一组键来查询Firestore中的多个文档 - How to use an array of keys to query multiple documents in Firestore Firebase firestore:如何查询相关文档,然后更新每个文档 - Firebase firestore: how to query relevant documents and then update each of them
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM