firebase-tools icon indicating copy to clipboard operation
firebase-tools copied to clipboard

database emulator seems not support "indexOn" rule setting.

Open idhowardgj94 opened this issue 2 years ago • 0 comments

Describe the bug Using realtime database with localhost emulator.

To Reproduce

  1. setting rules as follow:
{
  "rules": {
    ".read": "now < 1656777600000",  // 2022-7-3
    ".write": "now < 1656777600000",  // 2022-7-3
    "training": {
        "groups": {
          ".indexOn": ["groupName"]
        }  
      }
    }
}
  1. start firebase emulator:
firebase emulators:start --only auth,database
  1. insert some sample data:
{
  "training": {
    "groups": {
      "-N3mtNIVU7HCKcCnPGN5": {
        "groupName": "chest",
        "trainName": "dumbell incline chest press"
      },
      "-N3mtQu8tRutEIlzQBo8": {
        "groupName": "chest",
        "trainName": "dumbell literal chest press"
      },
      "-N3mtRBPMRW6WwZYuP0m": {
        "groupName": "chest",
        "trainName": "dumbell decline chest press"
      } 
    }
  }
}
  1. Try to search data by "groupName" (using clojureScript with shadow-cljs, firebase sdk version 9.8.1)
(defn get-chest-test
  []
  (let [db (ref (get-database) "/training/groups")]
    (-> (query db  (orderByChild "groupName") (equalTo "chest")))))

(-> (get-chest-test)
    (database/get)
    (.then #(do (js/console.log (.val %))))
    (.catch #(js/console.log %)))
  1. see the error in console (test in firefox, version 101.0)
Error: Index not defined, add ".indexOn": "groupName", for path "/training/groups", to the rules

connect to production works prefect without error.

Expected behavior

{
  "-N3mvAtQ0Q5ZUzDo-Jeg": {
    "groupName": "chest",
    "trainName": "dumbell incline chest press"
  },
  "-N3mvAteWJdlOeqA9UIY": {
    "groupName": "chest",
    "trainName": "dumbell literal chest press"
  },
  "-N3mvAtqBwEKMjja-xCD": {
    "groupName": "chest",
    "trainName": "dumbell decline chest press"
  }
}

Desktop (please complete the following information):

  • OS: Mac Monterey 12.2.1
  • Browser firefox
  • Version 101

idhowardgj94 avatar Jun 05 '22 08:06 idhowardgj94