Resume a query after the last document in Firestore












0















I have a collection of apartment documents in Firestore, where the id of each document is the date in milliseconds it was added (to keep them seemingly random).



Now I need to query those apartments based on the price (> or < than what the user chooses).



The app, which has a Tinder like interface (3 cards stacked), should load one apartment at a time when the user swipes the first one.



So I save the id of the last document apartment and query the price with an isGreaterThan query, and startAfter(lastId) and limit it to 1 document. However startAfter also requires an orderBy which needs to be on the same field as the isGreaterThan query. But as I said before, I need them to be random not ordered by the price field.



Is there any other way to "resume" a query, or start a query after the last document id or even position?



-



My first thought was to split the price into a boolean map. Except that I have other maps to query on (like distance or area) because range filters only work on 1 field, however an index is required for each combination (which would result in thousands of indexes, and firestore imposes a 200 indexes limit).



Then I've tried combining the id and price in a single field, but no success in finding a way to split it and retrieve the price and id without downloading the whole document which would be useless and inefficient (that's what I'm trying to avoid).



Range filters can't be used on multiple fields, so nothing to do here.



I know Firestore was built to be fast and scalable but I don't think this is a very complex query to do.



Thank you for your time.










share|improve this question

























  • What is the exact query the you are thinking of?

    – Alex Mamo
    Jan 18 at 18:22
















0















I have a collection of apartment documents in Firestore, where the id of each document is the date in milliseconds it was added (to keep them seemingly random).



Now I need to query those apartments based on the price (> or < than what the user chooses).



The app, which has a Tinder like interface (3 cards stacked), should load one apartment at a time when the user swipes the first one.



So I save the id of the last document apartment and query the price with an isGreaterThan query, and startAfter(lastId) and limit it to 1 document. However startAfter also requires an orderBy which needs to be on the same field as the isGreaterThan query. But as I said before, I need them to be random not ordered by the price field.



Is there any other way to "resume" a query, or start a query after the last document id or even position?



-



My first thought was to split the price into a boolean map. Except that I have other maps to query on (like distance or area) because range filters only work on 1 field, however an index is required for each combination (which would result in thousands of indexes, and firestore imposes a 200 indexes limit).



Then I've tried combining the id and price in a single field, but no success in finding a way to split it and retrieve the price and id without downloading the whole document which would be useless and inefficient (that's what I'm trying to avoid).



Range filters can't be used on multiple fields, so nothing to do here.



I know Firestore was built to be fast and scalable but I don't think this is a very complex query to do.



Thank you for your time.










share|improve this question

























  • What is the exact query the you are thinking of?

    – Alex Mamo
    Jan 18 at 18:22














0












0








0








I have a collection of apartment documents in Firestore, where the id of each document is the date in milliseconds it was added (to keep them seemingly random).



Now I need to query those apartments based on the price (> or < than what the user chooses).



The app, which has a Tinder like interface (3 cards stacked), should load one apartment at a time when the user swipes the first one.



So I save the id of the last document apartment and query the price with an isGreaterThan query, and startAfter(lastId) and limit it to 1 document. However startAfter also requires an orderBy which needs to be on the same field as the isGreaterThan query. But as I said before, I need them to be random not ordered by the price field.



Is there any other way to "resume" a query, or start a query after the last document id or even position?



-



My first thought was to split the price into a boolean map. Except that I have other maps to query on (like distance or area) because range filters only work on 1 field, however an index is required for each combination (which would result in thousands of indexes, and firestore imposes a 200 indexes limit).



Then I've tried combining the id and price in a single field, but no success in finding a way to split it and retrieve the price and id without downloading the whole document which would be useless and inefficient (that's what I'm trying to avoid).



Range filters can't be used on multiple fields, so nothing to do here.



I know Firestore was built to be fast and scalable but I don't think this is a very complex query to do.



Thank you for your time.










share|improve this question
















I have a collection of apartment documents in Firestore, where the id of each document is the date in milliseconds it was added (to keep them seemingly random).



Now I need to query those apartments based on the price (> or < than what the user chooses).



The app, which has a Tinder like interface (3 cards stacked), should load one apartment at a time when the user swipes the first one.



So I save the id of the last document apartment and query the price with an isGreaterThan query, and startAfter(lastId) and limit it to 1 document. However startAfter also requires an orderBy which needs to be on the same field as the isGreaterThan query. But as I said before, I need them to be random not ordered by the price field.



Is there any other way to "resume" a query, or start a query after the last document id or even position?



-



My first thought was to split the price into a boolean map. Except that I have other maps to query on (like distance or area) because range filters only work on 1 field, however an index is required for each combination (which would result in thousands of indexes, and firestore imposes a 200 indexes limit).



Then I've tried combining the id and price in a single field, but no success in finding a way to split it and retrieve the price and id without downloading the whole document which would be useless and inefficient (that's what I'm trying to avoid).



Range filters can't be used on multiple fields, so nothing to do here.



I know Firestore was built to be fast and scalable but I don't think this is a very complex query to do.



Thank you for your time.







flutter google-cloud-firestore






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 18 at 17:41







Adrian

















asked Jan 18 at 17:32









AdrianAdrian

6816




6816













  • What is the exact query the you are thinking of?

    – Alex Mamo
    Jan 18 at 18:22



















  • What is the exact query the you are thinking of?

    – Alex Mamo
    Jan 18 at 18:22

















What is the exact query the you are thinking of?

– Alex Mamo
Jan 18 at 18:22





What is the exact query the you are thinking of?

– Alex Mamo
Jan 18 at 18:22












0






active

oldest

votes











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%2f54258864%2fresume-a-query-after-the-last-document-in-firestore%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















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%2f54258864%2fresume-a-query-after-the-last-document-in-firestore%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

Liquibase includeAll doesn't find base path

How to use setInterval in EJS file?

Petrus Granier-Deferre