Menu
Who Do Is
  • Home
  • What
  • How
  • Is
  • Can
  • Are
  • Does
  • Do
  • Why
  • Who
  • Where
  • Which
  • Which
  • Should
  • Will
  • When
  • What’s
  • Did
Who Do Is

[ANSWERED] firebase – How do I ‘filter in’ firestore data satisfying ‘contains’ condition?

Posted on November 14, 2022

Solution 1 :

There is no query in Firestore that queries substrings as you want.

But there is a workaround for small datasets,which consists in to query all the data and save in a variable ( In your case, getting all the cities name ) and use contains() method like this:

Query query = fireStore.collection("Requests");
String str1 = document.getString("City");
String str2 = "Noida";
boolean b = str1.toLowerCase().contains(str2.toLowerCase());

And if you print the value of b, if it matches it will return true, if not false. But the above examples works well enough only for small datasets, as it’s not efficient for big datasets. In this case, as the official documentation recommends, you can enable full text search of your Cloud Firestore data, using a third-party search service like Algolia.

Solution 2 :

I don’t think so you can implement this directly. But I can suggest you a way to do. You can add another field to the document like “sector”
in which you can store the suburb of the city.

For eg. you can have city = “noida” and sector = “sector 32”.

Like this you can query for city and then get the sector
too.

Problem :

I just want to retrieve data according to node "City". Have a look to this image

Query query = fireStore.collection("Requests").whereEqualTo("City",Noida);

this query work when City node has the exact value (“Noida in this case”) but I want to retrieve all data where “City” containing require data

for example:
when City = Noida
this case is working.
What I want to do is

when City= Noida sec-32
and If I type Noida it still searches Noida sec-32

Comments

Comment posted by “array-contains-any”

Have you tried utilizing

Comment posted by Akshay Rajput

no, that a different thing, this provides me a value from every node in firebase with same name.

READ  [ANSWERED] java - Can't fully hide android material card background
Powered by Inline Related Posts

Comment posted by Akshay Rajput

thanks for your time. How many data entries are you considering in a small dataset?

Comment posted by Nibrass H

This only works for small datasets because the complexity is n^2, so if you have 1000 elements, the complexity will be 1000000. According to me, less than 100 elements will be considered as small datasets as it will have the complexity of 100 000 reads.

Comment posted by Akshay Rajput

Ok, now I get the logic. Thank you

Comment posted by Nibrass H

Could you please accept my answer if it was useful for you.

Comment posted by Akshay Rajput

Ohh sorry for that, can you also please mark this question up if you think this can help other

Recent Posts

  • How can I play with my cat without toys?
  • What is a bag pipe band called?
  • Are Honda Civics actually fast?
  • Are Yankee candles toxic?
  • How do I pair my Michael Kors smartwatch with my Android?

Recent Comments

No comments to show.

Archives

  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022

Categories

  • ¿Cómo
  • ¿Cuál
  • ¿Cuántas
  • ¿Cuánto
  • ¿Que
  • ¿Quién
  • 90” and 108” so you may have to round up to the nearest size.
  • and delete any Spotify folders from it. Once this is done
  • Android
  • Are
  • At
  • Bei
  • blink
  • C'est
  • Can
  • carbs
  • Comment
  • Did
  • Do
  • Does
  • During
  • For
  • Has
  • How
  • In
  • Is
  • Ist
  • Kann
  • Können
  • nouveau
  • On
  • or 108 inches.2020-08-03
  • Où
  • owning
  • Pourquoi
  • Puis-je
  • Quand
  • Quante
  • Quel
  • Quelle
  • Quelles
  • Quels
  • Qui
  • Should
  • Sind
  • Sollte
  • spiritual
  • tap the downward-facing arrow on the top left. A downward-facing arrow will appear underneath each song in the album; they'll turn green as the download completes.2020-07-28
  • Uncategorized
  • Wann
  • Warum
  • Was
  • Welche
  • Welcher
  • Welches
  • Welke
  • Wer
  • Were
  • What
  • What's
  • When
  • Where
  • Which
  • Who
  • Whose
  • Why
  • Wie
  • Will
  • Wo
  • Woher
  • you will receive two curtains each with the same measurements of width 66"" (168cm) x drop 54""(137cm).
  • you'll see a green downward-facing arrow next to each song.2021-02-26
©2023 Who Do Is | Powered by SuperbThemes & WordPress