Question: I'm trying to convert my app from Realtime DB to Firestore. I have the following code:

```
let db = Firestore.firestore()
var rideRequests: [DataSnapshot] = []

db.collection("RideRequests").getDocuments() { (querySnapshot, err) in
    if let err = err {
        print("Error getting documents: \(err)")
    } else {
        self.rideRequests.append(querySnapshot)
        self.tableView.reloadData()

        for document in querySnapshot!.documents {
            print("\(document.documentID) => \(document.data())")
        }
    }
}

```

I have a TableViewController but when I try to pass the response from the query I get the following error: 
*Cannot convert value of type 'QuerySnapshot?' to expected argument type 'DataSnapshot'*

What is the best way to convert this QuerySnapshot to a DataSnapshot as it was before or is it better to do a for loop and then to append them to an array?

Answer: 
The issue is that Firestore does not have a DataSnapshot. It has a QuerySnapshot and DocumentSnapshot. So you need to start migrating any code that received a DataSnapshot to receive a QuerySnapshot or DocumentSnapshot depending on the use case.

Suppose you previously did this to get the the data with the Firebase Real Time Database with a node is read with .childAdded

```
func printDataSnapshot(withSnapshot: DataSnapshot) {
   let key = withSnapshot.key
   let name = withSnapshot.childSnapshot("name").value as! String
   print(key, name)
}

```

with Firestore it's this if a collection (set of nodes) was read in

```
func printDocumentSnapshot(withQuerySnapshot: QuerySnapshot) {
   for doc in withQuerySnapshot.documents {
      let docId = withDocSnapshot.docId()
      let name = withDocSnapshot.get("name") as! String
      print(docId, name)
   }
}

```

or if you read a single document (node) with ref.getDocument...

```
func printDocumentSnapshot(withDocumentSnapshot: DocumentSnapshot) {
    let docId = withDocumentSnapshot.docId()
    let name = withDocumentSnapshot.get("name") as! String
    print(docId, name)
}

```

The [QuerySnapshot](https://firebase.google.com/docs/reference/ios/firebasefirestore/api/reference/Classes/FIRQuerySnapshot) is what's returned from a query and it contains DocumentSnapshots. You would generally enumerate over it to get the individual documents

> 
> A FIRQuerySnapshot contains zero or more FIRDocumentSnapshot objects.
>  It can be enumerated using for … in documentSet.documents and its size
>  can be inspected with isEmpty and count.
> 
> 
> 

In brief, data returned from Firestore via a call to '.documents' is returned in a QuerySnapshot which can be iterated over to get the individual DocumentSnapshots.

On the other hand, everything in the RTDB was a DataSnapshot, parent nodes, child nodes, etc.
Well you would get a little bit closer to that cast by unwrapping QuerySnapshot?. I usually use a 

```
guard let snap = snapshot else {return}

```

Is there a reason you can't declare your global array of DataSnapshots to be QuerySnapshots? I think DataSnapshots are unique to Realtime Database.