Home > Back-end >  firestore wherefield result is <FIRQuery> in swift
firestore wherefield result is <FIRQuery> in swift

Time:04-29

my code is here and result

  func documentField(){
        guard let uid = Auth.auth().currentUser?.uid else {
            return
        }
        print(uid)
        let db = Firestore.firestore().collection("collection")
        let data = db.orderby(by: "users").whereField("users", arraycontains: uid)
        print(data)
}
console outline

MNDJR2NOx1gOcxPGJ2xOUw3PHCM2
<FIRQuery: 0x6000032555e0>

i dont know where is my fault this query result is every time comig <FIRQuery: 0x6000032555e0>

enter image description here

CodePudding user response:

Your code creates a query, but doesn't execute it. So that means you're printing the query itself, not its results.

If you have a look at the documentation on getting documents from the database, you'll find this Swift example of how to do so:

db.collection("cities").whereField("capital", isEqualTo: true)
    .getDocuments() { (querySnapshot, err) in
        if let err = err {
            print("Error getting documents: \(err)")
        } else {
            for document in querySnapshot!.documents {
                print("\(document.documentID) => \(document.data())")
            }
        }
}

You're going to want to call getDocuments() on your query in the same way and process the results you get.

  • Related