私はGROUP1 『と『グループ2』で』「2016年5月20日」と'12/2016' 分の10たstartDateが等しい持っている木を取得したいFirebaseのパフォーマンス:orderByChildとequalToを複数回使用するほうが良いでしょうか?
'trees':
'group1': {
'tree1' : {
name: 'A first tree',
startDate: '10/20/2016'
},
'tree2' : {
name: 'A second tree',
startDate: '12/20/2016'
}
},
'group2': {
'tree3' : {
name: 'A third tree',
startDate: '12/20/2016'
},
'tree4' : {
name: 'A fourth tree',
startDate: '5/20/2016'
},
'tree5' : {
name: 'A fifth tree',
startDate: '10/20/2016'
}
}
}
として怒鳴る架空のデータベースを持っています。グループごとに2オプション
になってしまった、私は'12/2016' 分の10で再び
equalTo('5/20/2016')
を使用し、その後、それぞれの子キー 'たstartDate' を介して行く最初のクエリorderByChild('startDate')
ますvar startDates = ['5/10/2016','12/10/2016'] var groups = ['group1','group2'] groups.forEach(function(value, index) function() { firebase.database().ref('trees'+val); startDates.forEach(function(v,i) { userTaskRef.orderByChild('startDate').equalTo(l).once('child_added', function(result) { //some callback code }) })
})
ローカル
var startDates = ['5/10/2016','12/10/2016'] var groups = ['group1','group2'] groups.forEach(function(value, index) function() { firebase.database().ref('trees'+val); userTaskRef.once('value', function(rt) { // for-each for objects with jQuery $.map(rt.val(), function(value, index){ if (dates.indexOf(value.date) >= 0) { // select this tree } }) }) })
中で整理して 'グループ1' と 'グループ2' にすべての木を取得
どちらもうまくいけば、最初の方法ではローカルからサーバーへの旅行(グループ数*開始日数)が増えることに気付きました。 第二の方法は、グループの数と同じ実行が、だから私は、パフォーマンスとセキュリティ については、この特定のケースのための任意のアドバイスのために感謝し、すべてのデータを
を取得しますが(必要のないときに、他のツリーが読まれるべきではないと仮定)
乾杯一般に
よくフランク、あなたの答えをありがとう! –