Home > Enterprise >  Querying part of a string in firebase
Querying part of a string in firebase

Time:10-21

Is it possible to query just part of the name and get the data Like I have data 12345678 can I somehow just search for 1234?

data.whereEqualsto("data", 1234);

This is needed because the last numbers changes and the first ones doesn't.

CodePudding user response:

Is it possible to query just part of the name and get the data Like I have data 12345678 can I somehow just search for 1234?

Sure it is. When it comes to Firestore, you can simply use .startAt() as seen in the following query:

db.collection("collName").orderBy("data").startAt(1234);

When it comes to the Realtime Database, you can use .startAt() too, but as seen below:

db.child("nodeName").orderByChild("data").startAt(1234);

But remember, both queries will return elements that are greater than 1234. Since 12345678 is greater, it will be present in the result set.

  • Related