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?
Thanks
Use snapshot. exists() to check if the referenced database entry contains a child , irrespective of the value of the child.
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.
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.
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)
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