Removed unnecessary ObjectId conversion for the "chatId" field in the messages query. The database already stores "chatId" as a string, ensuring correct filtering and preventing potential mismatches.
Refactor MongoDB handling for cleaner and safer code.