Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FIREBASE WARNING: Using an unspecified index. Consider adding ".indexOn": "Keyboards" at / to your security rules for better performance

Why I'm Getting This error?:

FIREBASE WARNING: Using an unspecified index. Consider adding ".indexOn": "Keyboards" at / to your security rules for better performance

I have many Telegram Keyboards in my Firebase
1: I want to Fix This Error. ✔️
2: I Want to get and Console.log rock and rocky when telegram user typed rock,

const ref = db.ref('Keyboards/rock');  //keyboard 1
const ref = db.ref('Keyboards/morning');  //keyboard 2
const ref = db.ref('Keyboards/rocky');  //keyboard 3

Structure: enter image description here

Rules:

{
  "rules": {
    ".read": true,
    ".write": true,
      "Keyboards" : {
             ".indexOn": "Keyboards"
         }
  }
}

Code:

const ref = db.ref('/');
  ref.child('/').orderByChild('Keyboards').equalTo('rock').on("value", function(snapshot) {
    console.log(snapshot.val());
    key = snapshot.forEach(function(data) {
        console.log(data.key);
    });
});
like image 978
Saeed Heidarizarei Avatar asked Oct 15 '17 11:10

Saeed Heidarizarei


1 Answers

You are running the same query multiple times and ordering by the same child each time: Keyboards. Firebase is telling you that you probably want to index this search, kinda like telling the database that your are going to do this often so be prepared that I am going to do this search often.

It is explained here: Index your data

You can set up indexes under Database -> Rules in your project.

like image 130
rymdmaskin Avatar answered Sep 20 '22 00:09

rymdmaskin