title: How to get data from a map (object) Cloud Firestore document on Swift 4.2?
body: <p>I am using Cloud Firestore as a Database for my iOS App.</p>
  
  <p>I have an issue while I want to query my data when the document contains Maps (Object Type). I can not access the fields (say: firstName here) of a map (nameOnId) by having the simple query.</p>
  
  <p>My code is as bellow:</p>
  
  <pre><code>let db = Firestore.firestore()
      db.collection("userDetails").getDocuments() { (querySnapshot, err) in
  
          if let err = err {
              print("Error getting documents: \(err)")
          } else {
              for document in querySnapshot!.documents {
                  let results = document.data()
                  let result2 = results.compactMap({$0})
                  print("listedItems: \(document.documentID) =&gt; \(result2[0].value)") }}}
  </code></pre>
  
  <p>I read somewhere that in order to be able to access the values inside the map object, I need to flatten the map object, but having that does not give me access to them, the only thing that I could get into are a group of values inside the map so it only shows the keys and values for them like: </p>
  
  <pre><code>{
  firstName = "John";
  middleName = "British";
  middleName = "Citizen";
  gender = "M";
  DOB = "8 December 2000 at 00:00:00 UTC+11";
  }
  </code></pre>
  
  <p>the question is how to get access to a single value like "John" using the query?<a href="https://i.stack.imgur.com/C550a.jpg" rel="nofollow noreferrer">My data structure on Cloud Firestore</a></p>