根据否定查询Firestore集合 [英] Query Firestore collection based on negation

查看:35
本文介绍了根据否定查询Firestore集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在开发一个消息传递系统,用户可以互相阻止.这意味着我们需要能够在未阻止作者的地方查询消息.

We are developing a messaging system where the users are able to block each other. This means we need the ability to query message where the author is not blocked.

伪:从不在{list_of_blocked_ids}中author_id的消息中选择*

Pseudo: Select * from messages where author_id not in {list_of_blocked_ids}

由于Firestore不支持array_not_contains或任何其他否定方法,因此我们不确定如何构造此数据以进行此查询.

Since Firestore does not support array_not_contains or any other negation-methods we are quite unsure how to structure this data to be able to make this query.

任何帮助构建有关被阻止用户的信息的帮助.

Any help structuring this information about blocked users is appreciated.

推荐答案

要解决此问题,请根据有关

To solve this issue, according to the official documentation regarding Query limitations:

Cloud Firestore 不支持以下类型的查询:

  • 带有!= 子句的查询.在这种情况下,应将查询分为大于查询和小于查询.例如,尽管不支持查询子句where("age",!=","30"),您可以通过组合两个查询来获得相同的结果集,其中一个与子句where("age",<","30")和一个带有该子句的子句where("age",>",30).

    Queries with a != clause. In this case, you should split the query into a greater-than query and a less-than query. For example, although the query clause where("age", "!=", "30") is not supported, you can get the same result set by combining two queries, one with the clause where("age", "<", "30") and one with the clause where("age", ">", 30).

  • 因此,换句话说,Firestore中没有!= (不等于)运算符,也没有 arrayNotContains()函数.您唯一的选择是将查询分为 great-than less-than 查询,然后它将正常工作.

    So with other words, there is no != (not equal to) operator in Firestore nor a arrayNotContains() function. The only option that you have is to split your query into a greater-than and a less-than query and then it will work perfectly fine.

    这篇关于根据否定查询Firestore集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆