是否可以在 Firebase 上查询 !equalTo: null? [英] Is possible query an !equalTo: null on Firebase?

查看:21
本文介绍了是否可以在 Firebase 上查询 !equalTo: null?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此查询来验证我的 Firebase 上是否存在数据(使用 AngularFire2)

I'm using this query to verify if data exists on my Firebase (using AngularFire2)

let aux = this.afData.list("/drivers", { query: { orderByChild: '/accountHistory/approved', equalTo: null } });

效果很好,但我还需要进行反向查询.

Works pretty fine, but i also need to make an inverse query.

像这样

let aux = this.afData.list("/drivers", { query: { orderByChild: '/accountHistory/approved', equalTo: !null } });

问题是.第二个查询仅在值为 TRUE 时返回,我将 TIMESTAMP 存储在/driveruid/accountHistory/approved'

The problem is. This second query, only returns if the value is TRUE, i'm storing a TIMESTAMP on /driveruid/accountHistory/approved'

有没有办法只验证值是否存在?

There is any way to only verify if the Value exist or doesn't exist?

谢谢!

推荐答案

从 Firebase 文档中,使用 orderByChild 查询返回列表按以下顺序:-

From the Firebase docs, queries with orderByChild return lists in the following order :-

指定子键为空值的子项优先.

Children with a null value for the specified child key come first.

接下来是指定子键值为 false 的子项.如果多个子节点的值为 false,则它们按字典顺序按键排序.

Children with a value of false for the specified child key come next. If multiple children have a value of false, they are sorted lexicographically by key.

接下来是指定子键值为 true 的子项.如果多个子节点的值为 true,则它们按字典顺序按键排序.

Children with a value of true for the specified child key come next. If multiple children have a value of true, they are sorted lexicographically by key.

接下来是带有数值的孩子,按升序排序.如果指定子节点的多个子节点具有相同的数值,则按键对其进行排序.

Children with a numeric value come next, sorted in ascending order. If multiple children have the same numerical value for the specified child node, they are sorted by key.

字符串在数字之后,按字典顺序升序排列.如果指定子节点的多个子节点具有相同的值,则它们按字典顺序按键排序.

Strings come after numbers and are sorted lexicographically in ascending order. If multiple children have the same value for the specified child node, they are ordered lexicographically by key.

对象排在最后,并按字典顺序按键升序排序.

Objects come last and are sorted lexicographically by key in ascending order.

虽然您的第一个查询工作正常,但对于您的第二个查询,您可以尝试以下代码.

While your first query works fine, for your second query you could try the following code.

let aux = this.afData.list("/drivers", { query: { orderByChild: '/accountHistory/approved', startAt: false });

通过这样做,您的查询结果将不会包含您的子节点的值为 null 的数据.

By doing this, your query results would not contain data with a value of null for your child node.

不过,我建议您确保所有节点的子节点上的数据类型相同,以最大程度地减少 Class cast 异常和其他错误的机会.这更像是一种黑客攻击.

Though, I would recommend that you make sure that the data at the child node is of the same type for all the nodes to minimise the chances of Class cast exceptions and other errors. This is more of a hack.

这篇关于是否可以在 Firebase 上查询 !equalTo: null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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