All three read methods (database.read
, database.channel
and database.sync
) accepts references as strings, Reference
objects or Query
objects.
Using the last two options we can filter, sort and limit the results using the Firebase API methods (orderByChild
, equalTo
, limitToLast
, etc).
// Will only get users for which the `isAdmin` key is `true`:
const admins = yield call(
rsf.database.read,
firebase.database().reference('users').orderByChild('isAdmin').equalTo(true)
)
// Will get all users ordered by age:
const usersOrderedByAge = yield call(
rsf.database.read,
firebase.database().reference('users').orderByChild('age')
)
// Will synchronize the five youngest users:
yield fork(
rsf.database.sync,
firebase.database().reference('users').orderByChild('age').limitToFirst(5),
action
)
A similar approch works for firestore methods: getCollection
, syncCollection
and channel
.
They also accept firebase.firestore.CollectionReference and firebase.firestore.Query as argument.
// Will only synchronise users for which the `isAdmin` key is `true`:
yield fork(
rsf.firestore.syncCollection,
firestore.collection('users').where('isAdmin', '==', true),
action
)
// Get the 10 youngest users:
const users = yield call(
rsf.firestore.getCollection,
firestore.collection('users').orderBy('age').limit(10)
)