Ad
How To Get All Elements Whose Id Contains A Particular Substring?
I'm building a chat with firebase realtime database.
Let's say user1 has uid1 and user2 has uid2, their chatId will be uid1_uid2 (ordered asc). So the database chat/ looks like this:
chat {
uid1_uid2: [message, message...],
uid4_uid2:[message, message...],
uid5_uid1:[message, message...],
uid11_uid8:[message, message...]
}
Firebase rules are the following to allow only the interlocutors to have access to the conversation:
"chat": {
"$chatId": {
".write": "$chatId.contains(auth.uid)",
".read": "$chatId.contains(auth.uid)"
}
}
I want to get elements having uid1 in the chatId. So the expected return would be
{
uid1_uid2: [message, message...],
uid5_uid1:[message, message...]
}
Is there a way to get elements whose id contains a particular substring ? Something like...
databaseChat.child("contains uid1").on("value", snapshot => {
})
Ad
Answer
This is not possible. Realtime Database doesn't have substring queries. The best you can do is find prefix strings in values.
Ad
source: stackoverflow.com
Related Questions
- → How can I query Firebase for an equalTo boolean parameter?
- → How can I access nested data in Firebase with React?
- → Firebase simple blog (confused with security rules)
- → Removing item in Firebase with React, re-render returns item undefined
- → AngularJS Unknown Provider Error (Firebase & AngularFire)
- → How do you pass top level component state down to Routes using react-router?
- → "this" is null in firebase query function in reactjs
- → Angular Module Failed to Load
- → Multiple dex files define Lcom/google/android/gms/internal/zzrx;
- → Joining Firebase tables in React
- → How can I make add firepad to my reactjs project?
- → How to use Cloud Functions for Firebase to prerender pages for SEO?
- → React.js component has null state?
Ad