0

I want to create a chat app but actually I don't have any idea about using firebase with it,

I have created an index field and I want to calculate the length of documents to put their length as an index for every message.

I have got confused really & if you have another way which is better, feel free to write it.

https://i.stack.imgur.com/yfOLu.png

Renaud Tarnec
  • 79,263
  • 10
  • 95
  • 121
the coder
  • 400
  • 1
  • 9
  • 17

1 Answers1

0

If you want to store the number of texts that a user has added, I would recommend using a function that is triggered by an update in the collection.

Have another collection, say chats that would store the metadata of that chat, like the number of messages, date created etc. You can that increment the number of messages when a message is sent. Also include the chat id for the messages sent.

danwillm
  • 469
  • 3
  • 17
  • 1
    not sure if that was the posters question but you are definitely right with using server side events in function to do any kind of calculation and summary writes and stuff. – Logemann Oct 23 '19 at 11:06
  • @Marc yeah just realised I may have misinterpreted the question - my bad. The question was a little vague though... – danwillm Oct 23 '19 at 11:16
  • 1
    "a little" is kind of an understatement ;-) very vague.... indeed. – Logemann Oct 23 '19 at 11:54