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

Multi tool use
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.
javascript google-cloud-firestore
|
show 3 more comments
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.
javascript google-cloud-firestore
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 usedref.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
|
show 3 more comments
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.
javascript google-cloud-firestore
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
javascript google-cloud-firestore
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 usedref.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
|
show 3 more comments
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 usedref.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
|
show 3 more comments
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
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
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
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
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
j,8q,tZ osVHfaD4U2S8Mh33Mxxh9,CLlyOKO
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