The simplest way of storing chat messages is probably this:
message:
 -message1 {
   "user1"
   "user2"
   "message"
   "date"
  }
 -message2
 -message3
When the app grows in size (a lot of messages), and operations on database are done with .whereEqualTo are there any disadvantages of structuring chat app messages this way? Like with database iterating through all messages ?
Because if there are problems with this approach, i've seen for example this way of structuring database, that would segregate messages in different chat rooms
chats: {
    -chat1 {
      "lastMessage"
      "timestamp"
      "users": {user1, user2}
    }
    -chat2
    -chat3
  }
messages: {
 -chat1 {
  "message"
  "date"
 }
}
But in this example, adding new message would require user to make 2 write operations, one writing new message and one updating chat document with new lastMessage and timestamp client-side, or creating a cloud  function to update chat document with new values, when new message is added. 
So, is the first option valid, or should I go with something like the second example?