Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get all unique values from Firestore collection?

I have the following collection in Firestore:

Users (Collection)

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

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

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

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

Desired result: (John, Mary)

Thanks in advance!

like image 804
rfarias Avatar asked Dec 29 '17 14:12

rfarias


Video Answer


1 Answers

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.

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.

like image 192
Frank van Puffelen Avatar answered Sep 18 '22 11:09

Frank van Puffelen