Firestore chat-app: Is this a valid document structure for multi-recipient messages?

后端 未结 1 860
眼角桃花
眼角桃花 2021-01-02 21:52

Suppose a chat app has 10 million Firebase users, and hundreds of millions of messages.

I have a Firestore collection containing messages represented as documents in

相关标签:
1条回答
  • 2021-01-02 22:45

    Although many months later, for any future users, it does seem like the first attempt would likely work the best.

    Using a single static field for timestamp and a single static field for recipients means index will remain negligible and you won't have to think about them.

    To find all messages for a user, which seems as though it's your goal here:

    For example, if I want to know all messages for user 8293413 after 3:00 PM today, I could do it like this:

    This would simply look like this in pseudocode:

    firestore.collection('messages').where('recipient', 'array_contains', userId).where('time', '>', '3pm today'.get()
    

    This should be easy enough on performance, Firebase is optimized for the operators it provides, e.g. '==', '>=', 'array_contains'

    0 讨论(0)
提交回复
热议问题