I’m working on a React Native app, and trying to set up a user research in the database, based on a given text.
Here is my request code :
JavaScript
x
4
1
const ref = firebase.database().ref().child('allUsers');
2
const query = ref.orderByChild("name").startAt(text).endAt(text+'uf8ff').limitToFirst(20);
3
query.once('value',(snapshot)=>{ });
4
Database looks like :
JavaScript
1
12
12
1
allUsers
2
3
anUserUid
4
name: "a Name"
5
otherinfos
6
7
anOtherUserUid
8
name: "other Name"
9
otherinfos
10
11
otherusers
12
The query returns what I want, but I have an error on each query only saying “@firebase/database:”. And nothing else…
How can I fix it?
Advertisement
Answer
Most likely it is a warning about no index.
Try adding an index to your data. You can do that by adding the following to the database.rules.json
file:
JavaScript
1
8
1
{
2
"rules": {
3
"allUsers": {
4
".indexOn": ["name"]
5
}
6
}
7
}
8
And deploying.
Or by editing the rules in the Firebase Console.
As described in the indexing data documentation page