Google Firestore: Filter documents where sub-key is between given value









up vote
0
down vote

favorite












I am working on a browser game and I have a collection in firestore that looks like this:




title: "doc 1",
requirements:
level:
min: 2,
max: 3


,

title: "doc 2",
requirements:
level:
min: 6,
max: 8


,

title: "doc 3",
requirements:
level:
min: 8,
max: 9





Is there any way to query for all documents, that match a given level like when I have a level of 8 I only want to fetch the documents "doc 2" and "doc 3" because the level requirements match?



I tried with something like



ref.where("requirements.level.min", "<=", level);
ref.where("requirements.level.max", ">=", level);


I also tried to change the structure in my documents to this:




title: "doc 1",
requirements:
level: [2, 3]

,

title: "doc 2",
requirements:
level: [6, 7, 8]




and filter it like this



ref.where("requirements.level", "array-contains", level)


But firestore always returns me all documents.










share|improve this question





















  • Have you solved the issue?
    – Alex Mamo
    2 days ago










  • Unfortunately not
    – Ma Kobi
    2 days ago










  • Will it be helpful if I'll provide you an answer that implies some changes in your database structure?
    – Alex Mamo
    2 days ago










  • I am at the beginning of the development phase so I am thankful about every suggestion!
    – Ma Kobi
    2 days ago










  • Oh, sorry I missed that. You siad you have used ref.where("requirements.level", "array-contains", level) why do you say it always returns me all documents because is shouln't.
    – Alex Mamo
    2 days ago














up vote
0
down vote

favorite












I am working on a browser game and I have a collection in firestore that looks like this:




title: "doc 1",
requirements:
level:
min: 2,
max: 3


,

title: "doc 2",
requirements:
level:
min: 6,
max: 8


,

title: "doc 3",
requirements:
level:
min: 8,
max: 9





Is there any way to query for all documents, that match a given level like when I have a level of 8 I only want to fetch the documents "doc 2" and "doc 3" because the level requirements match?



I tried with something like



ref.where("requirements.level.min", "<=", level);
ref.where("requirements.level.max", ">=", level);


I also tried to change the structure in my documents to this:




title: "doc 1",
requirements:
level: [2, 3]

,

title: "doc 2",
requirements:
level: [6, 7, 8]




and filter it like this



ref.where("requirements.level", "array-contains", level)


But firestore always returns me all documents.










share|improve this question





















  • Have you solved the issue?
    – Alex Mamo
    2 days ago










  • Unfortunately not
    – Ma Kobi
    2 days ago










  • Will it be helpful if I'll provide you an answer that implies some changes in your database structure?
    – Alex Mamo
    2 days ago










  • I am at the beginning of the development phase so I am thankful about every suggestion!
    – Ma Kobi
    2 days ago










  • Oh, sorry I missed that. You siad you have used ref.where("requirements.level", "array-contains", level) why do you say it always returns me all documents because is shouln't.
    – Alex Mamo
    2 days ago












up vote
0
down vote

favorite









up vote
0
down vote

favorite











I am working on a browser game and I have a collection in firestore that looks like this:




title: "doc 1",
requirements:
level:
min: 2,
max: 3


,

title: "doc 2",
requirements:
level:
min: 6,
max: 8


,

title: "doc 3",
requirements:
level:
min: 8,
max: 9





Is there any way to query for all documents, that match a given level like when I have a level of 8 I only want to fetch the documents "doc 2" and "doc 3" because the level requirements match?



I tried with something like



ref.where("requirements.level.min", "<=", level);
ref.where("requirements.level.max", ">=", level);


I also tried to change the structure in my documents to this:




title: "doc 1",
requirements:
level: [2, 3]

,

title: "doc 2",
requirements:
level: [6, 7, 8]




and filter it like this



ref.where("requirements.level", "array-contains", level)


But firestore always returns me all documents.










share|improve this question













I am working on a browser game and I have a collection in firestore that looks like this:




title: "doc 1",
requirements:
level:
min: 2,
max: 3


,

title: "doc 2",
requirements:
level:
min: 6,
max: 8


,

title: "doc 3",
requirements:
level:
min: 8,
max: 9





Is there any way to query for all documents, that match a given level like when I have a level of 8 I only want to fetch the documents "doc 2" and "doc 3" because the level requirements match?



I tried with something like



ref.where("requirements.level.min", "<=", level);
ref.where("requirements.level.max", ">=", level);


I also tried to change the structure in my documents to this:




title: "doc 1",
requirements:
level: [2, 3]

,

title: "doc 2",
requirements:
level: [6, 7, 8]




and filter it like this



ref.where("requirements.level", "array-contains", level)


But firestore always returns me all documents.







javascript google-cloud-firestore






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 13:43









Ma Kobi

608317




608317











  • Have you solved the issue?
    – Alex Mamo
    2 days ago










  • Unfortunately not
    – Ma Kobi
    2 days ago










  • Will it be helpful if I'll provide you an answer that implies some changes in your database structure?
    – Alex Mamo
    2 days ago










  • I am at the beginning of the development phase so I am thankful about every suggestion!
    – Ma Kobi
    2 days ago










  • Oh, sorry I missed that. You siad you have used ref.where("requirements.level", "array-contains", level) why do you say it always returns me all documents because is shouln't.
    – Alex Mamo
    2 days ago
















  • Have you solved the issue?
    – Alex Mamo
    2 days ago










  • Unfortunately not
    – Ma Kobi
    2 days ago










  • Will it be helpful if I'll provide you an answer that implies some changes in your database structure?
    – Alex Mamo
    2 days ago










  • I am at the beginning of the development phase so I am thankful about every suggestion!
    – Ma Kobi
    2 days ago










  • Oh, sorry I missed that. You siad you have used ref.where("requirements.level", "array-contains", level) why do you say it always returns me all documents because is shouln't.
    – Alex Mamo
    2 days ago















Have you solved the issue?
– Alex Mamo
2 days ago




Have you solved the issue?
– Alex Mamo
2 days ago












Unfortunately not
– Ma Kobi
2 days ago




Unfortunately not
– Ma Kobi
2 days ago












Will it be helpful if I'll provide you an answer that implies some changes in your database structure?
– Alex Mamo
2 days ago




Will it be helpful if I'll provide you an answer that implies some changes in your database structure?
– Alex Mamo
2 days ago












I am at the beginning of the development phase so I am thankful about every suggestion!
– Ma Kobi
2 days ago




I am at the beginning of the development phase so I am thankful about every suggestion!
– Ma Kobi
2 days ago












Oh, sorry I missed that. You siad you have used ref.where("requirements.level", "array-contains", level) why do you say it always returns me all documents because is shouln't.
– Alex Mamo
2 days ago




Oh, sorry I missed that. You siad you have used ref.where("requirements.level", "array-contains", level) why do you say it always returns me all documents because is shouln't.
– Alex Mamo
2 days ago

















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',
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%2f53239581%2fgoogle-firestore-filter-documents-where-sub-key-is-between-given-value%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53239581%2fgoogle-firestore-filter-documents-where-sub-key-is-between-given-value%23new-answer', 'question_page');

);

Post as a guest














































































Popular posts from this blog

Top Tejano songwriter Luis Silva dead of heart attack at 64

ReactJS Fetched API data displays live - need Data displayed static

政党