firebase只获取密钥,然后获取数据 [英] firebase getting only keys then getting data
问题描述
我有一个数据结构如下在url
www.example.firebase.com /
{
companyList:{
compkey1:{
url1:somelink1,
url2:somelink2
},
compkey2:{
url1:somelink1,
url2:somelink2
}
}
}
我想要实现的是我要让firebase首先返回
compkey1
compkey2
和而不是任何孩子的数据如果用户希望看到一个特定的公司我希望他们去那个URL
像这样$ b $
www.example.firebase.com/companyList/compkey2
新增至firebase,所以请详细解释。
Firebase JavaScript客户端始终会检索完整的节点。它没有选择只检索密钥。
如果您只想检索公司的密钥/名称,您必须将它们存储在一个单独的节点。
$ b $ pre $ {
companyList:{
compkey1:{
url1 :somelink1,
url2:somelink2
},
compkey2:{
url1:somelink1,
url2 somelink2
}
},
companyKeys:{
compkey1:true,
compkey2:true
}
)
Firebase(和许多其他NoSQL数据库)的一个常见建议是以您的应用程序需要读取的方式对数据进行建模一>。在上面的例子中,你似乎需要阅读公司密钥列表,所以这就是你应该建模。
注意: Firebase REST API 确实有一个 shallow = true
参数,它将返回只有钥匙。但我建议通过对数据进行建模来解决问题。
i have a data structure as following at the url www.example.firebase.com/
{
"companyList" : {
"compkey1" : {
"url1":"somelink1",
"url2":somelink2
},
"compkey2" : {
"url1":"somelink1",
"url2":"somelink2"
}
}
}
What i want to achieve is that i want firebase to return first the list of companies which is
compkey1
compkey2
and not any child data
then if the user want to see a specific company i want them to go to that url like so
www.example.firebase.com/companyList/compkey2
new to firebase so explain as such.
The Firebase JavaScript client always retrieves complete nodes. It has no option to retrieve only the keys.
If you want to retrieve only the keys/names of the company, you'll have to store them in a separate node.
{
"companyList" : {
"compkey1" : {
"url1":"somelink1",
"url2":somelink2
},
"compkey2" : {
"url1":"somelink1",
"url2":"somelink2"
}
},
"companyKeys" : {
"compkey1": true,
"compkey2": true
}
}
A common recommendation in Firebase (and many other NoSQL databases) is to model your data in a way that your application will need to read it. In the above example, it seems like you need to read a list of company keys, so that is what you should model.
Note: the Firebase REST API does have a shallow=true
parameter that will return only the keys. But I recommend solving the problem by modeling the data differently instead.
这篇关于firebase只获取密钥,然后获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!