Skip to content Skip to sidebar Skip to footer

Firebase String Match At End Of Field

Imagin the following data: { 'name': 'Abcdef', 'age': 21 }, { 'name': 'Rodrigo', 'age': 24 }, { 'name': 'Matt', 'age': 30 }, { 'name': 'Def', 'age': 21 } How do I

Solution 1:

The method you're calling is called endAt(), but you are trying to use it as an endsWith(). That is a different type of operation, and is not supported by Firebase.

Firebase Database queries can only do prefix matching: find strings that start with a certain substring. There is no operation for postfix matching, nor for finding strings that contain a certain value.

If your use-case is really a postfix match, the common workaround would be to add a property that contains the reverse string and do a startAt().endAt() on that.

So:

{"name":"Abcdef","name_reverse":"fedcbA","age":21},{"name":"Def","name_reverse":"feD","age":21},

And then:

ref.orderByChild("name_reverse").startAt("fed").endAt("fed\uf8ff")

Post a Comment for "Firebase String Match At End Of Field"