Rayisooo
Rayisooo

Reputation: 122

Firebase firestore getting data from inside collection

Is there a way to grab the data from owner ID I'm not able to access the collection oath because the documentID is auto-generated and not a specific value I have control of

document screenshot

Upvotes: 1

Views: 67

Answers (1)

lukas
lukas

Reputation: 214

A possible option would be to query your documents and retrieve a specifc OwnerID like this. If you want to fetch all OwnerIDs from all of your documents just remove the 'whereField'.

Also check out the Firebase documentation for queries.

   let docRef = db.collection("YOURCOLLECTIONNAME")
   let query = docRef.whereField("OwnerID", isEqualTo:"VAL")

    query.getDocuments{ (querySnapshot, error) in
         if let error = error {
            print("\(error.localizedDescription)")
         }else {


              for documents in (querySnapshot?.documents)! {

                   if let owner = documents.get("OWnerID") as? String {
                      print(owner)
                    }
    }

Upvotes: 1

Related Questions