Firestore order by two fieldsRetrieving Firestore documents ordered by multiple fields is not workingFirestore order by two fields in one queryFirestore | Why do all where filters have to be on the same field?A limit clarification for the new FirestoreFirestore order by two fields in one queryHow to delete multiple documents from Cloud Firestore?Firestore order query based on order and boolReturn sorted fields from single Firestore documentAdd timestamp in Firestore documentsValidate reference in Firestore Security RulesFirestore Query is slow (when queried with a map-field sub field)How to paginate Cloud Firestore data with ReactJsQuerying the Firebase Firestore and ordering it causes an error

How to write papers efficiently when English isn't my first language?

Short story about space worker geeks who zone out by 'listening' to radiation from stars

For a non-Jew, is there a punishment for not observing the 7 Noahide Laws?

Purchasing a ticket for someone else in another country?

Escape a backup date in a file name

Customer Requests (Sometimes) Drive Me Bonkers!

What is the difference between "behavior" and "behaviour"?

Method to test if a number is a perfect power?

How to Reset Passwords on Multiple Websites Easily?

System.debug(JSON.Serialize(o)) Not longer shows full string

What Brexit proposals are on the table in the indicative votes on the 27th of March 2019?

Did the DC-9 ever use RATO in revenue service?

CREATE opcode: what does it really do?

Avoiding estate tax by giving multiple gifts

Why are there no referendums in the US?

Fine Tuning of the Universe

Would this custom Sorcerer variant that can only learn any verbal-component-only spell be unbalanced?

Crossing the line between justified force and brutality

Go Pregnant or Go Home

Implement the Thanos sorting algorithm

Closest Prime Number

Hostile work environment after whistle-blowing on coworker and our boss. What do I do?

Is exact Kanji stroke length important?

Why Were Madagascar and New Zealand Discovered So Late?



Firestore order by two fields


Retrieving Firestore documents ordered by multiple fields is not workingFirestore order by two fields in one queryFirestore | Why do all where filters have to be on the same field?A limit clarification for the new FirestoreFirestore order by two fields in one queryHow to delete multiple documents from Cloud Firestore?Firestore order query based on order and boolReturn sorted fields from single Firestore documentAdd timestamp in Firestore documentsValidate reference in Firestore Security RulesFirestore Query is slow (when queried with a map-field sub field)How to paginate Cloud Firestore data with ReactJsQuerying the Firebase Firestore and ordering it causes an error













3















In firestore I'm wondering if there is a way to have a hueristic1 and get all data between two hueristic1 values but order the results based on a hueristic2.



I ask because the data at bottom of both pages



https://firebase.google.com/docs/firestore/query-data/order-limit-data



https://firebase.google.com/docs/firestore/query-data/query-cursors



there seems to be slightly contradictory documentation.



What I want to be able to do is



Ref.startAt(some h1 value).endAt(some second h1 value).orderBy(h2). 


I know I'd probably have to index by h1 but even then I'm not sure if there is a way to do this.










share|improve this question


























    3















    In firestore I'm wondering if there is a way to have a hueristic1 and get all data between two hueristic1 values but order the results based on a hueristic2.



    I ask because the data at bottom of both pages



    https://firebase.google.com/docs/firestore/query-data/order-limit-data



    https://firebase.google.com/docs/firestore/query-data/query-cursors



    there seems to be slightly contradictory documentation.



    What I want to be able to do is



    Ref.startAt(some h1 value).endAt(some second h1 value).orderBy(h2). 


    I know I'd probably have to index by h1 but even then I'm not sure if there is a way to do this.










    share|improve this question
























      3












      3








      3


      0






      In firestore I'm wondering if there is a way to have a hueristic1 and get all data between two hueristic1 values but order the results based on a hueristic2.



      I ask because the data at bottom of both pages



      https://firebase.google.com/docs/firestore/query-data/order-limit-data



      https://firebase.google.com/docs/firestore/query-data/query-cursors



      there seems to be slightly contradictory documentation.



      What I want to be able to do is



      Ref.startAt(some h1 value).endAt(some second h1 value).orderBy(h2). 


      I know I'd probably have to index by h1 but even then I'm not sure if there is a way to do this.










      share|improve this question














      In firestore I'm wondering if there is a way to have a hueristic1 and get all data between two hueristic1 values but order the results based on a hueristic2.



      I ask because the data at bottom of both pages



      https://firebase.google.com/docs/firestore/query-data/order-limit-data



      https://firebase.google.com/docs/firestore/query-data/query-cursors



      there seems to be slightly contradictory documentation.



      What I want to be able to do is



      Ref.startAt(some h1 value).endAt(some second h1 value).orderBy(h2). 


      I know I'd probably have to index by h1 but even then I'm not sure if there is a way to do this.







      firebase google-cloud-firestore






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 19 '17 at 20:33









      BlueBlue

      4001422




      4001422






















          1 Answer
          1






          active

          oldest

          votes


















          3














          Update:



          I didn't test this well enough to see that is doesn't produce the desired ordering. The OP asked the question again and got an answer from a Firebase team member:




          Because Cloud Firestore doesn't support ordering by a different field
          than the supplied inequality, you won't be able to sort by name
          directly from the query. Instead you'd need to sort client-side once
          you've fetched the data.





          The API supports the capability you want, although I don't see an example in the documentation that shows it.



          The ordering of the query terms is important. Suppose you have a collection of cities and the fields of interest are population (h1) and name (h2). To get the cities with population in range 1000 to 2000, ordered by name, the query would be:



          citiesRef.orderBy("population").orderBy("name").startAt(1000).endAt(2000)


          This query requires a composite index, which you can create manually in the console. Or as the documentation there indicates, the system will help you:




          Instead of defining a composite index manually, run your query in your
          app code to get a link for generating the required index.







          share|improve this answer

























          • "run your query in your app code to get a link for generating the required index." what does this mean? in my case the query is Cloud function how do i do it?

            – Raghunandan Ghagarvale
            Jun 26 '18 at 5:06











          • @RaghunandanGhagarvale: On the client side, running the query produces log messages that contain the link with instructions. Check your cloud function execution log. It may be the same there.

            – Bob Snyder
            Jun 26 '18 at 14:03











          • @Bob Snyder, I attempted the above implementation. However, I'm seeing empty results. Query: .collection(ALL_COLLECTION).orderBy(TIMESTAMP) .orderBy(QUALITY_SCORE).startAt(getTimeframe(WEEK)). Composite Index: timestamp DESC qualityScore DESC. Perhaps I'm setting up my composite index improperly? I did not see an auto-generated link in Android Studio's Logcat.

            – Adam Hurwitz
            Aug 26 '18 at 5:02












          • I figured out what I was doing incorrectly. I wasn't seeing the auto-generated link in Android Studio before because I was looking under Error logs, not Verbose, etc.

            – Adam Hurwitz
            Aug 26 '18 at 6:12











          • It appears you are correct though, upon further review I cannot filter out based on my TIMESTAMP.

            – Adam Hurwitz
            Aug 26 '18 at 7:32










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47381713%2ffirestore-order-by-two-fields%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          3














          Update:



          I didn't test this well enough to see that is doesn't produce the desired ordering. The OP asked the question again and got an answer from a Firebase team member:




          Because Cloud Firestore doesn't support ordering by a different field
          than the supplied inequality, you won't be able to sort by name
          directly from the query. Instead you'd need to sort client-side once
          you've fetched the data.





          The API supports the capability you want, although I don't see an example in the documentation that shows it.



          The ordering of the query terms is important. Suppose you have a collection of cities and the fields of interest are population (h1) and name (h2). To get the cities with population in range 1000 to 2000, ordered by name, the query would be:



          citiesRef.orderBy("population").orderBy("name").startAt(1000).endAt(2000)


          This query requires a composite index, which you can create manually in the console. Or as the documentation there indicates, the system will help you:




          Instead of defining a composite index manually, run your query in your
          app code to get a link for generating the required index.







          share|improve this answer

























          • "run your query in your app code to get a link for generating the required index." what does this mean? in my case the query is Cloud function how do i do it?

            – Raghunandan Ghagarvale
            Jun 26 '18 at 5:06











          • @RaghunandanGhagarvale: On the client side, running the query produces log messages that contain the link with instructions. Check your cloud function execution log. It may be the same there.

            – Bob Snyder
            Jun 26 '18 at 14:03











          • @Bob Snyder, I attempted the above implementation. However, I'm seeing empty results. Query: .collection(ALL_COLLECTION).orderBy(TIMESTAMP) .orderBy(QUALITY_SCORE).startAt(getTimeframe(WEEK)). Composite Index: timestamp DESC qualityScore DESC. Perhaps I'm setting up my composite index improperly? I did not see an auto-generated link in Android Studio's Logcat.

            – Adam Hurwitz
            Aug 26 '18 at 5:02












          • I figured out what I was doing incorrectly. I wasn't seeing the auto-generated link in Android Studio before because I was looking under Error logs, not Verbose, etc.

            – Adam Hurwitz
            Aug 26 '18 at 6:12











          • It appears you are correct though, upon further review I cannot filter out based on my TIMESTAMP.

            – Adam Hurwitz
            Aug 26 '18 at 7:32















          3














          Update:



          I didn't test this well enough to see that is doesn't produce the desired ordering. The OP asked the question again and got an answer from a Firebase team member:




          Because Cloud Firestore doesn't support ordering by a different field
          than the supplied inequality, you won't be able to sort by name
          directly from the query. Instead you'd need to sort client-side once
          you've fetched the data.





          The API supports the capability you want, although I don't see an example in the documentation that shows it.



          The ordering of the query terms is important. Suppose you have a collection of cities and the fields of interest are population (h1) and name (h2). To get the cities with population in range 1000 to 2000, ordered by name, the query would be:



          citiesRef.orderBy("population").orderBy("name").startAt(1000).endAt(2000)


          This query requires a composite index, which you can create manually in the console. Or as the documentation there indicates, the system will help you:




          Instead of defining a composite index manually, run your query in your
          app code to get a link for generating the required index.







          share|improve this answer

























          • "run your query in your app code to get a link for generating the required index." what does this mean? in my case the query is Cloud function how do i do it?

            – Raghunandan Ghagarvale
            Jun 26 '18 at 5:06











          • @RaghunandanGhagarvale: On the client side, running the query produces log messages that contain the link with instructions. Check your cloud function execution log. It may be the same there.

            – Bob Snyder
            Jun 26 '18 at 14:03











          • @Bob Snyder, I attempted the above implementation. However, I'm seeing empty results. Query: .collection(ALL_COLLECTION).orderBy(TIMESTAMP) .orderBy(QUALITY_SCORE).startAt(getTimeframe(WEEK)). Composite Index: timestamp DESC qualityScore DESC. Perhaps I'm setting up my composite index improperly? I did not see an auto-generated link in Android Studio's Logcat.

            – Adam Hurwitz
            Aug 26 '18 at 5:02












          • I figured out what I was doing incorrectly. I wasn't seeing the auto-generated link in Android Studio before because I was looking under Error logs, not Verbose, etc.

            – Adam Hurwitz
            Aug 26 '18 at 6:12











          • It appears you are correct though, upon further review I cannot filter out based on my TIMESTAMP.

            – Adam Hurwitz
            Aug 26 '18 at 7:32













          3












          3








          3







          Update:



          I didn't test this well enough to see that is doesn't produce the desired ordering. The OP asked the question again and got an answer from a Firebase team member:




          Because Cloud Firestore doesn't support ordering by a different field
          than the supplied inequality, you won't be able to sort by name
          directly from the query. Instead you'd need to sort client-side once
          you've fetched the data.





          The API supports the capability you want, although I don't see an example in the documentation that shows it.



          The ordering of the query terms is important. Suppose you have a collection of cities and the fields of interest are population (h1) and name (h2). To get the cities with population in range 1000 to 2000, ordered by name, the query would be:



          citiesRef.orderBy("population").orderBy("name").startAt(1000).endAt(2000)


          This query requires a composite index, which you can create manually in the console. Or as the documentation there indicates, the system will help you:




          Instead of defining a composite index manually, run your query in your
          app code to get a link for generating the required index.







          share|improve this answer















          Update:



          I didn't test this well enough to see that is doesn't produce the desired ordering. The OP asked the question again and got an answer from a Firebase team member:




          Because Cloud Firestore doesn't support ordering by a different field
          than the supplied inequality, you won't be able to sort by name
          directly from the query. Instead you'd need to sort client-side once
          you've fetched the data.





          The API supports the capability you want, although I don't see an example in the documentation that shows it.



          The ordering of the query terms is important. Suppose you have a collection of cities and the fields of interest are population (h1) and name (h2). To get the cities with population in range 1000 to 2000, ordered by name, the query would be:



          citiesRef.orderBy("population").orderBy("name").startAt(1000).endAt(2000)


          This query requires a composite index, which you can create manually in the console. Or as the documentation there indicates, the system will help you:




          Instead of defining a composite index manually, run your query in your
          app code to get a link for generating the required index.








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 28 '17 at 23:06

























          answered Nov 20 '17 at 1:47









          Bob SnyderBob Snyder

          27.1k466121




          27.1k466121












          • "run your query in your app code to get a link for generating the required index." what does this mean? in my case the query is Cloud function how do i do it?

            – Raghunandan Ghagarvale
            Jun 26 '18 at 5:06











          • @RaghunandanGhagarvale: On the client side, running the query produces log messages that contain the link with instructions. Check your cloud function execution log. It may be the same there.

            – Bob Snyder
            Jun 26 '18 at 14:03











          • @Bob Snyder, I attempted the above implementation. However, I'm seeing empty results. Query: .collection(ALL_COLLECTION).orderBy(TIMESTAMP) .orderBy(QUALITY_SCORE).startAt(getTimeframe(WEEK)). Composite Index: timestamp DESC qualityScore DESC. Perhaps I'm setting up my composite index improperly? I did not see an auto-generated link in Android Studio's Logcat.

            – Adam Hurwitz
            Aug 26 '18 at 5:02












          • I figured out what I was doing incorrectly. I wasn't seeing the auto-generated link in Android Studio before because I was looking under Error logs, not Verbose, etc.

            – Adam Hurwitz
            Aug 26 '18 at 6:12











          • It appears you are correct though, upon further review I cannot filter out based on my TIMESTAMP.

            – Adam Hurwitz
            Aug 26 '18 at 7:32

















          • "run your query in your app code to get a link for generating the required index." what does this mean? in my case the query is Cloud function how do i do it?

            – Raghunandan Ghagarvale
            Jun 26 '18 at 5:06











          • @RaghunandanGhagarvale: On the client side, running the query produces log messages that contain the link with instructions. Check your cloud function execution log. It may be the same there.

            – Bob Snyder
            Jun 26 '18 at 14:03











          • @Bob Snyder, I attempted the above implementation. However, I'm seeing empty results. Query: .collection(ALL_COLLECTION).orderBy(TIMESTAMP) .orderBy(QUALITY_SCORE).startAt(getTimeframe(WEEK)). Composite Index: timestamp DESC qualityScore DESC. Perhaps I'm setting up my composite index improperly? I did not see an auto-generated link in Android Studio's Logcat.

            – Adam Hurwitz
            Aug 26 '18 at 5:02












          • I figured out what I was doing incorrectly. I wasn't seeing the auto-generated link in Android Studio before because I was looking under Error logs, not Verbose, etc.

            – Adam Hurwitz
            Aug 26 '18 at 6:12











          • It appears you are correct though, upon further review I cannot filter out based on my TIMESTAMP.

            – Adam Hurwitz
            Aug 26 '18 at 7:32
















          "run your query in your app code to get a link for generating the required index." what does this mean? in my case the query is Cloud function how do i do it?

          – Raghunandan Ghagarvale
          Jun 26 '18 at 5:06





          "run your query in your app code to get a link for generating the required index." what does this mean? in my case the query is Cloud function how do i do it?

          – Raghunandan Ghagarvale
          Jun 26 '18 at 5:06













          @RaghunandanGhagarvale: On the client side, running the query produces log messages that contain the link with instructions. Check your cloud function execution log. It may be the same there.

          – Bob Snyder
          Jun 26 '18 at 14:03





          @RaghunandanGhagarvale: On the client side, running the query produces log messages that contain the link with instructions. Check your cloud function execution log. It may be the same there.

          – Bob Snyder
          Jun 26 '18 at 14:03













          @Bob Snyder, I attempted the above implementation. However, I'm seeing empty results. Query: .collection(ALL_COLLECTION).orderBy(TIMESTAMP) .orderBy(QUALITY_SCORE).startAt(getTimeframe(WEEK)). Composite Index: timestamp DESC qualityScore DESC. Perhaps I'm setting up my composite index improperly? I did not see an auto-generated link in Android Studio's Logcat.

          – Adam Hurwitz
          Aug 26 '18 at 5:02






          @Bob Snyder, I attempted the above implementation. However, I'm seeing empty results. Query: .collection(ALL_COLLECTION).orderBy(TIMESTAMP) .orderBy(QUALITY_SCORE).startAt(getTimeframe(WEEK)). Composite Index: timestamp DESC qualityScore DESC. Perhaps I'm setting up my composite index improperly? I did not see an auto-generated link in Android Studio's Logcat.

          – Adam Hurwitz
          Aug 26 '18 at 5:02














          I figured out what I was doing incorrectly. I wasn't seeing the auto-generated link in Android Studio before because I was looking under Error logs, not Verbose, etc.

          – Adam Hurwitz
          Aug 26 '18 at 6:12





          I figured out what I was doing incorrectly. I wasn't seeing the auto-generated link in Android Studio before because I was looking under Error logs, not Verbose, etc.

          – Adam Hurwitz
          Aug 26 '18 at 6:12













          It appears you are correct though, upon further review I cannot filter out based on my TIMESTAMP.

          – Adam Hurwitz
          Aug 26 '18 at 7:32





          It appears you are correct though, upon further review I cannot filter out based on my TIMESTAMP.

          – Adam Hurwitz
          Aug 26 '18 at 7:32



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f47381713%2ffirestore-order-by-two-fields%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

          Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

          2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived