I am trying to implement a realtime chat into my iOS application. I am using MessageKit and following this tutorial: https://medium.com/@ibjects/simple-text-chat-app-using-firebase-in-swift-5-b9fa91730b6c
The tutorial is fore firebase but I am trying to convert it to work with my MongoDb backend as best I can. One of the issues I am facing is trying to replicate the following code:
self.docReference = doc.reference
//fetch it's thread collection
doc.reference.collection("thread")
.order(by: "created", descending: false)
.addSnapshotListener(includeMetadataChanges: true, listener: { (threadQuery, error) in
if let error = error {
print("Error: \(error)")
return
} else {
self.messages.removeAll()
for message in threadQuery!.documents {
let msg = Message(dictionary: message.data())
self.messages.append(msg!)
print("Data: \(msg?.content ?? "No message found")")
}
I am unsure how I would make a listener for changes to a collection thread? The way my app works is it makes Http Requests and I have a running server that makes the actual mongo queries, so I need a way to setup a listener that works with that. Thanks for all the help!
edit:
This is the kind of schema I am trying to emulate, the examples is in Firebase, the only part I am having trouble figuring out is how theres a collection nested within a document? How would I go about doing that in Mongo