Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Cloud Firestore: Query regular Expression

I'm using google firebase's firestore. I was wondering if there was a way to query for documents where a property/field matches a regex. Something like this:

var username_regex = /^[a-z0-9\-\_\.]{3,}$/;
firebase.firestore().collection('users')
.where("username", "==", username_regex)
.get()

Is this possible yet? if not, how likely is it that google could implement something like this?

like image 450
ryanwaite28 Avatar asked Dec 09 '17 20:12

ryanwaite28


1 Answers

You can add a Firestore rule that will allow you to read only valid usernames:

match /users/{userID} {
  allow read: if resource.data.username.matches('^[a-z0-9-_.]{3,30}$');
}
like image 175
Bohdan Didukh Avatar answered Oct 04 '22 10:10

Bohdan Didukh