Firebase上可能会查询!equalTo:null? [英] Is possible query an !equalTo: null on Firebase?

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

问题描述

我使用这个查询来验证我的Firebase中是否存在数据(使用AngularFire2)
$ b $ pre $ let $ aux = this。 afData.list(/ drivers,{query:{orderByChild:'/ accountHistory / approved',equalTo:null}});

工作得很好,但我也需要做一个反向查询。 b

像这样

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

问题是。第二个查询,只有当值为 TRUE 才会返回,我在/ driveruid / accountHistory / approved中存储了一个TIMESTAMP。



任何方式只验证价值存在或不存在?

谢谢!

解决方案

在Firebase文档中, orderByChild 的查询按以下顺序返回列表:


具有指定子键的空值的子元素优先。



接下来是指定子键值为false的子元素。如果多个孩子的值为假,则按键按字典顺序排序。



接下来是指定子键的值为true的子元素。如果多个孩子的值为true,则按键按字典顺序排序。

接下来是具有数值的孩子,按升序排序。如果多个子项对于指定的子节点具有相同的数值,则按键排序。

字符串在数字之后,按照字典顺序排列。如果多个子节点对于指定的子节点具有相同的值,则按键以字典顺序排列。



对象最后一个按键按升序排列。当你的第一个查询正常工作时,对于第二个查询,你可以尝试下面的代码:




b

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

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



虽然,我建议您确保在子节点的数据是相同类型所有的节点尽量减少类抛出异常和其他错误的机会。这是更多的黑客。


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.

Like this

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

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?

Thanks!

解决方案

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.

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.

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 });

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

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天全站免登陆