Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase, query with "a child exists" as a condition?

I have a database like this (photo attached): Trip has BIDS, and awardedBid. I use awardedBid!=null as a way to determine the trip is still available for bidding. However, I don't know how to query for that condition, so I have to hack by creating another field bidDone so I can use .equalTo, like this

mRootReference.child(CHILD_TRIPS).child(mTripKey).orderByChild(BID_DONE).equalTo(true)

However I feel that's unsafe when I have to use 2 keys to denote just one thing since it's bug-prone (I did create one myself in the attached screenshot where bidDone = false where it should be true).

Is there any cleaner way for that task: query with condition that a string exist?

enter image description here

Thanks

like image 631
EyeQ Tech Avatar asked Jul 18 '16 15:07

EyeQ Tech


People also ask

How do I check my child's firebase?

Use snapshot. exists() to check if the referenced database entry contains a child , irrespective of the value of the child.

What does getKey () do firebase?

Calling the getKey() method on this reference will return the auto-generated key which may then be used to store a corresponding value. Using Firebase to generate unique keys in this way is also of particular use when an app has multiple users creating child nodes at the same path in the tree.

What is ref and child in firebase?

Oct 19, 2019 at 8:24. 2. @appu what refers to ref() and child(), they are completely different in a meaning that ref() is the one who actually creates the connection to database, after which you can use child() to specify the exact location. Without ref(), child() is basically useless.


1 Answers

You can remove your attribute bidDone and using startAt() to get all the child having awardedBid not null:

ref.orderByChild("awardedBid").startAt("")

or this to get only the child without bid

ref.orderByChild("awardedBid").endAt(null)
like image 100
Devid Farinelli Avatar answered Nov 08 '22 13:11

Devid Farinelli