0
"vehicles" : {
          "-KbwlIGLm6dxffPJoJJB" : {            
            "fuel" : "petrol",
            "groups" : {
              "-KdWh_9KVF16efcSdrji" : true,
              "-Kdb1G720MDgbuR3nPBL" : true
            },
            "make" : "Honda",
            "model" : "City",
            "name" : "Honda City",            
            "speed_limit" : 100,
            "tank_size" : 32,
            "type" : "car"
          },
          "-KdU-BlfEdqzKxFjGI3D" : {            
            "fuel" : "petrol",
            "groups" : {
              "-KdWh_9KVF16efcSdrji" : true
            },
            "make" : "yamaha",
            "model" : "FZ",
            "name" : "Yamaza FZ",            
            "speed_limit" : 60,
            "tank_size" : 12,
            "type" : "bike"
          }          
        }

I want to retrieve results where groups has the -KdWh_9KVF16efcSdrji and the key must equal to true.

vehicles_ref.child("groups").orderByChild("-KdWh_9KVF16efcSdrji").equalTo(true).on
("value", function (snapshot) {
    console.log(snapshot.val());
});

But currently I'm getting NULL for the above criteria.

i have changed query

vehicles_ref.orderByChild("/groups/-KdWh_9KVF16efcSdrji").equalTo(true).on("value", function (snapshot) {
    console.log(snapshot.val());
});

now getting results, but now getting warning

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

how to add index to remove this warning ?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Paavalan Babu
  • 31
  • 2
  • 10
  • You're trying to put the vehicles into categories. While you can add the indexes for that, it'd mean you need to add a new index for every category. Instead, have a look at my answer here for a better way of modeling categories: http://stackoverflow.com/questions/40656589/firebase-query-if-child-of-child-contains-a-value – Frank van Puffelen Feb 23 '17 at 04:28
  • We are running a large system with this warning. We're doing just fine. It's not an error. – Ali Gajani Feb 23 '17 at 04:44

1 Answers1

0

I also had that warning that I sent firebase, and I was filtering queries in the queries looking for items with the same id. The warning message ".indexOn" refers to the rule in your database, which should be checked by adding ".indexOn" to the group you are trying to sort the items in.

{

  "scores": {

    "bruhathkayosaurus" : 55,
    "lambeosaurus" : 21,
    "linhenykus" : 80,
    "pterodactyl" : 93,
    "stegosaurus" : 5,
    "triceratops" : 22
        }
}

Because the names of the dinosaurs are just the keys. we can add a .value rule to our node / scores to optimize our queries:

{

  "rules": {

    "scores": {
      ".indexOn": ".value"
         }
      }
}

you can use the following link: https://firebase.google.com/docs/database/security/indexing-data?hl=es-419

Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123
Franz Medrano
  • 49
  • 1
  • 2