如何从Firestore集合中获取所有唯一值? [英] How to get all unique values from Firestore collection?

查看:48
本文介绍了如何从Firestore集合中获取所有唯一值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Firestore中有以下收藏集:

I have the following collection in Firestore:

用户(集合)

Users (Collection)
-- user1 (Document)
-----name: "John"
-----age: 23

-- user2 (Document)
-----name: "Mary"
-----age: 25

-- user3 (Document)
-----name: "John"
-----age: 20

问题:如何查询Firestore,以便获得集合中所有唯一的名称?

Question: How can I query Firestore so that I get all unique names in the collection?

所需结果 :(约翰,玛丽)

提前谢谢!

推荐答案

没有特定的API从Cloud Firestore检索唯一值.您将必须检索所有相关文档,并在自己的代码中确定唯一的名称.

There is no specific API to retrieve unique values from Cloud Firestore. You will have to retrieve all relevant documents and determine the unique names in your own code.

或者,考虑添加具有唯一名称的文档,并在每次写入时进行更新.这是NoSQL数据库中非常普遍的方法,但是如果您不熟悉它们,可能需要一些时间来习惯.

Alternatively, consider adding a document with unique names and update that with every write. This is a quite common approach in NoSQL databases, butmay take some getting used to if you're new to them.

这篇关于如何从Firestore集合中获取所有唯一值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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