question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Database emulator does not support .indexOn

See original GitHub issue

[REQUIRED] Environment info

firebase-tools: 3.3.0

Platform: Windows

[REQUIRED] Test case

I used the official docs example for orderByChild https://firebase.google.com/docs/database/security/indexing-data?authuser=0.

// client code
      db.ref('dinosaurs').set({
        "lambeosaurus": {
          "height": 2.1,
          "length": 12.5,
          "weight": 5000
        },
        "stegosaurus": {
          "height": 4,
          "length": 9,
          "weight": 2500
        }
      }).then(()=>{
        db.ref('dinosaurs').orderByChild('height').startAt(3).once('value').then(s => console.log(s.val()));
      })
// security rules
{
  "rules": {
    ".read": true,
    ".write": true,
    "dinosaurs": {
      ".indexOn": [
        "height",
        "length"
      ]
    }
  }
}

[REQUIRED] Steps to reproduce

Running the code above against a real database shows stegosaurus: {height: 4, length: 9, weight: 2500}.

Running it against the emulator shows both stegosaurus: {height: 4, length: 9, weight: 2500} and a warning:

logger.ts:86 [2020-02-18T17:08:23.851Z]  @firebase/database: FIREBASE WARNING: Using an unspecified index. Your data will be downloaded and filtered on the client. Consider adding ".indexOn": "height" at /dinosaurs to your security rules for better performance. 

[REQUIRED] Expected behavior

I expected .indexOn to be supported, or perhaps for the emulator to mention it was not using the index, or for this limitation to be listed somewhere. Maybe it’s already documented but I couldn’t find it in the official docs or the issue tracker.

[REQUIRED] Actual behavior

The emulator silently ignores the index and the client warns that there is no index.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:22 (12 by maintainers)

github_iconTop GitHub Comments

2reactions
yuchenshicommented, Feb 18, 2020

Could you please check if the rules are properly loaded in the the emulator by curl localhost:9000/.settings/rules.json?ns=your-database-name -H 'Authorization: Bearer owner'? (Replace localhost:9000 with your emulator host/port and your-database-name with your database name).

Also, please double check that you’re connecting to the same database in your web app as specified to Firebase CLI. On the web app, make sure you’re specifying the db name like databaseURL: "http://localhost:9000/?ns=foo" (note the ns parameter). And when starting Firebase CLI, make sure to use firebase emulators:start --project foo, because Firebase CLI automatically set the security rules only for the database whose name matches the project ID. If you are accessing a different database, that database will have the default open security rules and no index entries.

0reactions
samtsterncommented, Mar 19, 2020

I am going to send a PR to add explicit encoding to all readFileSync calls in this codebase.

Also I think it should be utf8 not utf-8 but I guess Node is forgiving?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Index Your Data | Firebase Realtime Database - Google
If you know in advance what your indexes will be, you can define them via the .indexOn rule in your Firebase Realtime Database...
Read more >
Why does this Firebase ".indexOn" not work? - Stack Overflow
So I have data like so:
Read more >
Firebase Admin SDK for PHP - Read the Docs
If auto-discovery is not wanted, you can generate a private key file in JSON ... Database Emulators are currently supported in this PHP...
Read more >
firebase/index.d.ts - UNPKG
* Error codes are strings using the following format: `"service/string-code"`. 43, * Some examples include `"app/no- ...
Read more >
Securing Your Firebase RealTime Database?
This has multiple advantages: clients are not responsible for ... Firebase is a cloud database storage service that can be accessed from any ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found