title: Firestore startAfter last snapshot is not working, if 2 or more documents have same field value
body: <p>I have a collection named 'test', which has multiple documents.
  Each document has a unique name and a number field.
  I have implemented pagination using query cursor. The query to get initial documents is as follows:</p>
  
  <pre><code>let lastDocument={};
   ref.collection("test").orderBy('number', 'desc').limit(3).get()
    .then(snapshot =&gt; {
      lastDocument = snapshot.docs[snapshot.docs.length-1];
    })
    .catch(err =&gt; {
      console.log("Error getting documents", err);
    });
  </code></pre>
  
  <p>After getting the lastDocument, I paginate it as follows:    </p>
  
  <pre><code>ref.collection("test").orderBy('number', 'desc').startAfter(lastDocument).limit(3); //lastDocument has the last document of the snapshot that was retrieved.
  </code></pre>
  
  <p>In my collection, if there are 2 or more documents which have same value of field 'number', then I don't get that document in the query result. Whereas, If I change the value of the field 'number', so as to make all the documents unique, I get all the results in batches(according to the limit clause) properly.</p>
  
  <p>It's mentioned in the document as well, that, if multiple fields have same population value, the query won't work <a href="https://firebase.google.com/docs/firestore/query-data/query-cursors#paginate_a_query" rel="nofollow noreferrer">https://firebase.google.com/docs/firestore/query-data/query-cursors#paginate_a_query</a></p>
  
  <p>How should I modify the query, so as to get all documents in the result, even if 2 or more documents have same values for the field used in orderBy?</p>
  
  <p>I am using:</p>
  
  <p><code>"react-native-firebase": "^5.5.6",
  "react-native": "^0.59.8",
  "firebase": "^6.6.1",</code></p>
  
  <blockquote>
    <p>Update: I have tested the queries on JSbin and it returns proper
    results. I have issues when I use it in react native app with
    react-native-firebase library. The pattern that I have recognised so
    far is as follows: let's say, there are documents like below
    {id:a,num:1},{id:b,num:2},{id:c,num:2},{id:d,num:2},{id:e,num:3},{id:f,num:4}
    Then if I query for the first set with orderBy('num','desc') and limit
    as 2, I'll get [a,b]. Now, if I query with the startAfter last
    document as 'b' and limit as 2, then it will skip all the documents
    after b, which have num same as that of b (i.e 2). So, it'll skip doc
    [c,d] and return me [e,f]. This works fine on jsbin, but not on react
    native using react-native-firebase library.</p>
  </blockquote>
  
  <p>Please find the exact output for the code <a href="https://jsbin.com/zunetehoxa/edit?js,console" rel="nofollow noreferrer">here</a> on react-native below:</p>
  
  <blockquote>
    <p>"Got all results"</p>
    
    <p>"wbXwyLJheRfYXXWlY46j => {\"index\":2,\"number\":2}"</p>
    
    <p>"kGC5cYPN1nKnZCcAb9oQ => {\"index\":6,\"number\":2}"</p>
    
    <p>"8Ek8iWCDQPPJ5s2n8PiQ => {\"index\":4,\"number\":2}"</p>
    
    <p>"mr7MdAygvuheF6AUtWma => {\"index\":1,\"number\":1}"</p>
    
    <p>"RCO5SvNn4fdoE49OKrIV => {\"index\":3,\"number\":1}"</p>
    
    <p>"CvVG7VP1hXTtcfdUaeNl => {\"index\":5,\"number\":1}"</p>
    
    <p>"Got first page"</p>
    
    <p>"wbXwyLJheRfYXXWlY46j => {\"index\":2,\"number\":2}"</p>
    
    <p>"kGC5cYPN1nKnZCcAb9oQ => {\"index\":6,\"number\":2}"</p>
    
    <p>"Got second page"</p>
    
    <p>"mr7MdAygvuheF6AUtWma => {\"index\":1,\"number\":1}"</p>
    
    <p>"RCO5SvNn4fdoE49OKrIV => {\"index\":3,\"number\":1}"</p>
  </blockquote>
  
  <p><strong>Note that it has skipped : "8Ek8iWCDQPPJ5s2n8PiQ => {\"index\":4,\"number\":2}"</strong></p>
  
  <p><strong>Encountered one more issue in react-native-firebase library:</strong>
  If there is a map structure in the documents like below:</p>
  
  <pre><code>{
   subscribedUsers:{
   +1656666:true,
   +1657878:false,
   +1677676:true
   }
  }
  </code></pre>
  
  <p>Now if I fire a query like below:</p>
  
  <blockquote>
    <p>db.collection("ownerUsers").where(<code>subscribedUsers.${phonenumber}</code> ,
    '==' , true).limit(3).get();</p>
  </blockquote>
  
  <p>The query returns 3 results.Now, if I try to get the next 3 results using startAfter clause like below, it works fine with firebase, but doesn't work with react-native-firebase library:</p>
  
  <blockquote>
    <p>db.collection("ownerUsers").where(subscribedUsers.${phonenumber} , '==' , true).startAfter(last).limit(3).get()</p>
  </blockquote>
  
  <p>then I get the below error:</p>
  
  <pre><code>[Info] 11-10 21:38:42.631 21908 21967 I ReactNativeJS: 'Error getting documents', { [Error: Firestore: Client specified an invalid argument. (firestore/invalid-argument).]
  </code></pre>