Documentation : firebase.database.Reference
── Query Methods ── firebase.database.Query
orderByChild (key) Order children at location by the value of specified grandchild key.
orderByKey () Order children at location by child keys.
orderByValue () Order children at location by child values.
limitToFirst (num) Max number of children to return from the beginning. (Based on orderBy*.)
limitToLast (num) Max number of children to return from the end. (Based on orderBy*.)
startAt (val, key) Return children who's val (and key, optionally) are >= the specified val (and key, optionally).
endAt (val, key) Return children who's val (and key, optionally) are <= the specified val (and key, optionally).
equalTo (val) Return children who's val is == the specified val.
── Exemples ──
import * as firebase from 'firebase'
{
"users": {
"1": {
"name": "David",
"email": "david@email.com",
"age": "38",
"location": "SF",
"age_location": "99_SF",
},
"9": {
"name": "Alice",
"email": "alice@email.com",
"age": "28",
"location": "Paris",
"age_location": "28_Paris",
}
}
}
// Get a reference to the root of the Database
const rootRef = firebase.database().ref
// > The key of a root reference is null
const key = rootRef.key; // key === null
// 1. Select a user by UID
const oneRef = rootRef.child('users').child('1')
// 2. Find a user by email address
const twoRef = rootRef.child('users').orderByChild('email').equalTo('alice@email.com')
// 3. Limit to 10 users
const treeRef = rootRef.child('users').limitToFirst(10)
// 4. Get all users names that start with 'd'
const fourRef = rootRef.child('users').orderByChild('name').startAt('D').endAt('D\uf8ff')
// 5. Get all users ages who are less than 50
const fiveRef = rootRef.child('users').orderByChild('age').endAt('49')
// 6. Get all users who are greater than 50
const sixRef = rootRef.child('users').orderByChild('age').startAt('51')
// 7. Get all users ages who are between 20 and 100
const seveRef = rootRef.child('users').orderByChild('age').startAt(20).endAt(100)
// 8. Get all users who are 28 and live in Paris
const eightRef = rootRef.child('users').orderByChild('age_location').equalTo('28_Paris')
// 8. Get all users who are 28 and live in Paris
const eightRef = rootRef.child('users').orderByChild('age_location').equalTo('28_Paris')
is not working for me :s