Firebase,用“一个孩子存在"查询作为条件? [英] Firebase, query with "a child exists" as a condition?

查看:52
本文介绍了Firebase,用“一个孩子存在"查询作为条件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的数据库(附照片): 行程具有BIDSawardedBid.我使用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?

谢谢

推荐答案

您可以删除属性bidDone并使用

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆