检查文档字段中Cloud Firestore中的特定值 [英] Check a document field for a specific value in Cloud Firestore

查看:56
本文介绍了检查文档字段中Cloud Firestore中的特定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用自定义用户名创建用户注册.我将用户的用户名存储在Firestore中的用户文档上.如何验证用户集中已经存在的用户名?

I want to create a user registration with custom usernames. I store the user's username on a user document in Firestore. How can I validate a username already exists in my Users Collection?

也许有人已经有用于响应式表单验证的代码段了?

Maybe someone already have snippet for reactive form validation?

推荐答案

没有有效的方法来检查集合中所有文档的特定值.您将必须依次阅读每个文档,然后进行检查.从性能和成本的角度来看,这都是令人望而却步的.

There is no efficient way to check all documents in a collection for a specific value. You would have to read each document in turn, and check them. That is prohibitive both from a performance and a cost standpoint.

您可以做的是创建一个附加集合(通常称为反向索引或反向映射),在其中您使用用户名作为文档的名称,并使用用户的UID作为文档的数据.然后,您可以轻松地检查

What you can instead do is create an additional collection (typically called a reverse index, or reverse map) where you use the username as the name of the document, and (for example) the user's UID as the data of the document. You can then easily check if a username is already taken by checking for the existence of a document with that specific name, which is a direct access lookup and thus highly scaleable.

由于您已标记google-cloud-datastore;如果您确实也在寻找该数据库的答案,请检查 Google数据存储区中的唯一电子邮件地址.

Since you tagged with google-cloud-datastore; if you are indeed looking for an answer for that database too, check Unique email in Google Datastore.

这篇关于检查文档字段中Cloud Firestore中的特定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆