I am working on developing a chat application using Angular/Meteor technology.
Query
Is there a method to identify when changes occur in the MongoDB Cursor? Is there an event that gets triggered when a new row is added?
When I send a message to another user in the chat app, the new conversation gets displayed in the list (indicating an update in MongoDB), but I need a way to detect this update dynamically in order to populate the new chat with the appropriate details like username. Although refreshing the page shows the updated chat, I want to achieve this dynamically.
chats: Mongo.Cursor<Chat>;
Since I am relatively new to Meteor, I am still trying to grasp some aspects of it. However, the code snippet below shows what I have implemented so far:
let promise: Promise<Mongo.Cursor<Chat>> = this.findChats();
promise.then((data) => {
this.chats = data;
this.chats.observe({
changed: (newChat, oldChat) => this.disposeChat(oldChat),
removed: (chat) => this.disposeChat(chat)
});
this.addNewChatAndShowMessage();
});
I believe I need to make modifications within the observe
function. Even though I expected the disposeChat
function to be triggered when a new chat
is added, it does not happen as anticipated.
Any suggestions would be highly appreciated.