firebase-tools: Database emulator does not support .indexOn
[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.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 22 (12 by maintainers)
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:9000with your emulator host/port andyour-database-namewith 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 thensparameter). 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.