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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With