I have a Firebase Realtime Database with the below structure.
notes
   noteId-1345
      access
         author: 1234567890
         members
             1234567890: 0 <--- Author
             0987654321: 1 <--- Member
      data
         title
When fetching data with the below code I only get "notes" I have access to.
database.ref('notes')
  .orderByChild(`access/members/${uid}`)
  .equalTo(0)
  .on('value', (snaps) => {
I wish to get "notes" where I am either author or member by using the code below. But this results in getting ALL notes, even those I am neither author or member in (?)
database.ref('notes')
  .orderByChild(`access/members/${uid}`)
  .endAt(99)
  .on('value', (snaps) => {
My database rules are:
"notes": {
  //Indexes
  ".indexOn": ["data/title", "access/author", "access/members"],
  
  //entry-level access
  ".read": "
    auth.uid !== null && query.endAt === 99
  ",
  "$note_id": {
    ".write": "        
            //Create new if authenticated
            !data.exists() && auth.uid !== null
            //Update if author or member
      ||(data.exists() && newData.exists() && data.child('access/members').child(auth.uid).exists())
            //Delete if author
            ||(data.exists() && !newData.exists() && data.child('access').child('author').val() === auth.uid)        
    ",      
    "data": {
      //access
      ".read": "
        //if author or assigned user
        data.parent().child('access').child('author').val() === auth.uid ||
        data.parent().child('access/members').child(auth.uid).exists()
      ",
      ".write": "
        //if author or assigned user
        data.parent().child('access').child('author').val() === auth.uid ||
        data.parent().child('access/members').child(auth.uid).exists()          
      "          
    },
    "access" : {
      //access
      ".read" : "
        (auth.uid !== null) &&
        (
          data.child('author').val() === auth.uid
        ||
          data.child('members').child(auth.uid).exists()
        )
      "
    }
This this expected bahaviour or am I doing something wrong?
Kind regards /K
UPDATE:
If changing my access rule to
  //entry-level access
  ".read": "auth.uid !== null && query.startAt === 0
and my code to
database.ref('notes')
  .orderByChild(`access/members/${uid}`)
  .startAt(0)
  .on('value', (snaps) => {
everything seems to be working!
I am a bit worried my access rules allow users to read all "notes", since the first code using .endAt(99) fetched ALL "notes".
How can I make sure users can ONLY read "notes" where they are listed as authors or members?
Kind regards /K
 
    