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
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
add a comment |
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
add a comment |
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
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
firebase google-cloud-firestore
asked Nov 19 '17 at 20:33
BlueBlue
4001422
4001422
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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.
"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
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
"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
add a comment |
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.
"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
add a comment |
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.
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.
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
add a comment |
"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
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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