admin管理员组

文章数量:1289877

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!

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!

Share Improve this question edited Jul 3, 2017 at 23:58 Frank van Puffelen 600k85 gold badges889 silver badges859 bronze badges asked Jul 3, 2017 at 18:06 Igor Santos de LimaIgor Santos de Lima 1771 silver badge11 bronze badges 3
  • Possible duplicate of is it possible query data that are not equal to the specified condition? – Roman C Commented Jul 3, 2017 at 18:36
  • There is no any value check. But what values do you store in there? You might be able to get somewhere with startAt("a").endAt("z").limitToFirst(1) (depending on the range of values you can have). – Frank van Puffelen Commented Jul 4, 2017 at 0:00
  • @FrankvanPuffelen I appreciate the help! My question had only 2 cases. * The Absence of data * The existence of a TIMESTAMP Rohan's suggestion worked very well! Thanks Again! – Igor Santos de Lima Commented Jul 4, 2017 at 11:13
Add a ment  | 

1 Answer 1

Reset to default 13

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

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

Children with a value of false for the specified child key e 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 e next. If multiple children have a value of true, they are sorted lexicographically by key.

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

Strings e 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 e 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 remend 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.

本文标签: javascriptIs possible query an equalTo null on FirebaseStack Overflow