Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Does key exited cover a document deleted from firestore? #142

Open
sgallo0692 opened this issue Feb 10, 2021 · 0 comments
Open

Comments

@sgallo0692
Copy link

sgallo0692 commented Feb 10, 2021

Trying to ensure when a document is deleted from firestore, that results in the map annotation from my observe query being removed.

I'm maintaining the results of .documentedEntered in a published array

    @Published var mapStreams = [Stream]()
    
    init() {
        loadData()
    }
    
    func loadData() {
        let geoResults = geoFire.query(withCenter: GeoPoint(latitude: 35.111521, longitude: -40.987951), radius: 5000)
        
        let _ = geoResults.observe(.documentEntered, with: {(key, location) in
            if let key = key, let loc = location {
                let doc = playbackRef.document("\(key)")
                doc.getDocument { (document, error) in
                    
                    let result = Result {
                        try document?.data(as: Stream.self)
                    }
                    
                    switch result {
                        case .success(let stream):
                            if let stream = stream {
                                // A `City` value was successfully initialized from the DocumentSnapshot.
                                self.mapStreams.append(stream)
                            } else {
                                // A nil value was successfully initialized from the DocumentSnapshot,
                                // or the DocumentSnapshot was nil.
                                print("Document does not exist")
                            }
                        case .failure(let error):
                            // A `City` value could not be initialized from the DocumentSnapshot.
                            print("Error decoding stream: \(error)")
                    }
                }
            }
        })
}

What I realized is this only is accurate when my app is opened, but it's not acting as a snapshotListener if a document is modified or deleted. How do I ensure I monitor firestore for deletes or updates to a document?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant