Google Cloud Firestore:查询正则表达式

时间:2017-12-09 20:32:46

标签: javascript firebase google-cloud-firestore

我正在使用google firebase的firestore。我想知道是否有办法查询属性/字段匹配正则表达式的文档。像这样:

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

这可能吗?如果没有,谷歌有多大可能实现这样的东西?

1 个答案:

答案 0 :(得分:0)

您可以添加允许您只读取有效用户名的Firestore规则:

match /users/{userID} {
  allow read: if resource.data.username.matches('^[a-z0-9-_.]{3,30}$');
}