Google Cloud Firestore:查询正则表达式

6

我正在使用谷歌 Firebase 的 Firestore。我想知道是否有一种方法可以查询属性/字段与正则表达式匹配的文档。类似于这样:

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

这个现在可行吗?如果不行,谷歌可能会实施这样的功能有多大可能性?
1个回答

2
您可以添加一个Firestore规则,只允许读取有效的用户名:
match /users/{userID} {
  allow read: if resource.data.username.matches('^[a-z0-9-_.]{3,30}$');
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接