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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With