title: Firestore orderBy security rule
body: <p>I've just started using Firestore and am trying to create a security rule to support this kind of query from my app (Android/kotlin)</p>
  
  <pre><code>firestoreDb.collection("messages").whereEqualTo("room_id", "c_1")
      .orderBy("timestamp", Query.Direction.ASCENDING)
  </code></pre>
  
  <p>Structure of my database is:</p>
  
  <pre><code>room
     -{roomId}
        -members [] //this is an array of strings
  messages
     -{messageId}
        -timestamp
        -room_id
        -message_text
  </code></pre>
  
  <p>The security rule looks as follows:</p>
  
  <pre><code>service cloud.firestore {
    match /databases/{database}/documents {
      match /messages/{messageId} {
          allow read: if request.auth.uid in get(/databases/$(database)/documents/rooms/$(resource.data.room_id)).data.members &amp;&amp; 
          request.query.orderBy == "timestamp"
      }
    }
  }
  </code></pre>
  
  <p>If I don't use the orderBy part everything works fine and I get a successful response. However after applying orderBy in code, I need to add the orderBy rule to the firestore security rules. Unfortunately I wasn't able to find any example of the syntax, how that should be defined.</p>
  
  <p>This is the <a href="https://firebase.google.com/docs/firestore/security/rules-query" rel="nofollow noreferrer">official documentation</a> I'm using as a reference, but there's only an example for <code>request.query.limit</code>, from which it isn't clear how the <code>request.query.orderBy</code> should work.</p>
  
  <p>Any help much appreciated
  Cheers</p>