根据Firebase中的类别检索数据 [英] Retrieve data based on categories in Firebase
问题描述
比方说,我有以下数据结构:
我的查询的目标是给定的国家/地区名称,我想检索其目标数组包含此国家/地区的所有用户。例如: 有人知道如何用Firbase Angular做这样的查询吗? Firebase没有与数组中的项匹配的查询运算符。事实上:Firebase建议不要使用阵列来处理您所遇到的情况。而是像这样存储数据: 现在您可以查询具有目的地Jordan的用户: 然后将这个绑定到您的AngularJS作用域: 这种类型的数据结构称为索引,您经常会发现需要添加特定的索引到您的NoSQL数据库,以适应您的应用程序的查询要求。看到这个关于NoSQL数据建模的文章为好介绍这个话题。 I'm new with Firebase and I have a question about retrieving some data.
Lets say I'm having the following data structure: The goal of my query is for a given country name I want to retrieve all the users that their destinations array contain this country. For example:
for the query of "Jordan" it will retrieve: user2 and user3. Anybody know how can I do such a query with Firbase Angular? Firebase doesn't have a query operator that matches items in an array. In fact: Firebase recommends against using arrays for situations like the one you have. Instead, store the data like this: Now you can query users that have destination Jordan with: And then bind this to your AngularJS scope with: This type of data structure is called an index and you'll often find you need to add specific indexes to your NoSQL database to fit the querying requirements of your app. See this article on NoSQL data modeling for a good introduction on the topic. 这篇关于根据Firebase中的类别检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
用于查询Jordan,它将检索:user2和user3。
顾问国家:{
user1:{
destinations: {
安哥拉:真,
澳大利亚:真
}
},
用户2:{
目的地:{
安哥拉:真,
奥地利:真实,
约旦:真实
}
},
用户3:{
目的地:{
奥地利:真实
埃及:真实的,
Jordan:真实的
}
}
}
var users = ref.child('advisors-国家')。orderByChild('destinations / Jordan')
.equalTo(true);
$ scope.users = $ firebaseArray(users);
advisors-countries: {
user1: {
destinations: {
Angola: true,
Australia: true
}
},
user2: {
destinations: {
Angola: true,
Austria: true,
Jordan: true
}
},
user3: {
destinations: {
Austria: true
Egypt: true,
Jordan: true
}
}
}
var users = ref.child('advisors-countries').orderByChild('destinations/Jordan')
.equalTo(true);
$scope.users = $firebaseArray(users);