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:
- Created 4 years ago
- Comments:22 (12 by maintainers)
Top 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 >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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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'
? (Replacelocalhost:9000
with your emulator host/port andyour-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 thens
parameter). And when starting Firebase CLI, make sure to usefirebase 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.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
notutf-8
but I guess Node is forgiving?