Firebase:如何判断字段是否唯一?

时间:2019-03-14 10:28:09

标签: javascript firebase vuejs2 google-cloud-firestore

我正在尝试进行一次Firestore查询,以告诉我值是否唯一(例如用户名)

isUnique

但这似乎不起作用?有想法吗?

此问题的一部分可能源于vuelidate,其中 async isUnique(value) { /** previousVuelidateUsernameCall and * previousVuelidateUsernameValue are added to * prevent too many calls. If cache is added to the `get()` * the first call occurs too soon and the cache is never updated. */ if (this.previousVuelidateUsernameCall === value) { return this.previousVuelidateUsernameValue } let results = await db.collection('users') .where('username', '==', value) .get() //{source: 'cache'} .then((snapshot) => { return snapshot.size === 0 }) this.previousVuelidateUsernameValue = results this.previousVuelidateUsernameCall = value return results } }, 是文本字段上的验证函数。

{{1}}

0 个答案:

没有答案