Created
December 23, 2013 09:22
-
-
Save shakirullahi/8093974 to your computer and use it in GitHub Desktop.
Setting priority while pushing in firebase
//credit:kato
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ref = new Firebase('https://<example>.firebaseio.com/rewards').push(); | |
ref.setWithPriority({ | |
name: 'apple', | |
otherKey: 'somevalue', | |
... | |
}, 'apple', function(err) { | |
if( error ) { console.error(err); } | |
else { | |
fetchValue(); | |
} | |
}); | |
function fetchValue() { | |
// wait for the set to complete before fetching data | |
new Firebase('https://<example>.firebaseio.com/rewards') | |
.startAt('apple') | |
.endAt('apple') | |
.once('value', function(snap) { | |
console.log('found:', snap.val()); // logs: "found null" | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment