Firebase,用“一个孩子存在"查询作为条件? [英] Firebase, query with "a child exists" as a condition?
问题描述
我有一个这样的数据库(附照片):
行程具有BIDS
和awardedBid
.我使用awardedBid!=null
作为确定旅程仍可进行出价的一种方式.但是,我不知道如何查询该条件,因此我不得不通过创建另一个字段bidDone
来破解,以便可以使用.equalTo
,例如
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)
但是,当我不得不使用2个键来表示一件事时,我认为这是不安全的,因为它容易出错(我确实在所附的屏幕快照中创建了一个自己的屏幕,其中bidDone = false
应为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?
谢谢
推荐答案
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)
这篇关于Firebase,用“一个孩子存在"查询作为条件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!