How to sort in Firebase with Multiple priority? -


i have data in firebase:

mainnode       pictures            -jjr1pypnhbocjsif_0j                 user: user1                 view: 20            -jjr1padfxtus_wctj2a                 user: user2                 view: 500       users            -user1                 name: 'austin'            -user2                 name: 'bucha' 

and have 2 cases.

  1. get pictures of userx
  2. show pictures view

i can desired result case#1 if run , setpriority userid

new firebase("https://xxx.firebaseio.com/pictures")     .startat('user1')     .endat('user1')     .once('value', show); 

however, lost when want all pictures sorted view limit 10. since setpriority can used once, how can result case#2? please shed me light here better approach , in advance.

for pictures of user x, store list (an index) of user's photos in separate location:

/my_photos/$user_id/$photo_id/<true> /photos/$photo_id/<data> (with priority viewed) 

now fetch viewed, use call so:

new firebase(url).child('photos').endat().limit(10).once('value', function(snap) {    console.log('most viewed', snap.val()); }); 

and ones belonging me:

new firebase(url).child('my_photos/kato').on('child_added', function(indexsnap) {    new firebase(url).child('photos/'+indexsnap.name()).once('value', function(photosnap) {       console.log('one of photos', console.log(photosnap.val());    }); }); 

a tool firebaseindex or firebase.util.join can abstract process of joining index , data:

var fb = new firebase(url); var joined = new firebaseindex( fb.child('my_photos/kato'), fb.child('photos') ); joined.on('child_added', function(snap) {    console.log('one of photos', snap.val()); }); 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -