user12481721
user12481721

Reputation:

Firestore for storing thousands of messages in a user-to-user chat?

I just realised that Firestore has 1MB per document limit. Can someone suggest me how the big conversations are handled without erasing the old messages? Here's my current structure.

Defining the conversation name (users should always end to the same conversation):

var A = 'Chris' // User 1
var B = 'Nick' // User 2

var conversation = (A < B ? A + '_' + B : B + '_' + A)

console.log(A + ', ' + B + ' => ' + conversation)

A = 'Nick' // User 1
B = 'Chris' // User 2

var conversation = (A < B ? A + '_' + B : B + '_' + A)

console.log(A + ', ' + B + ' => ' + conversation)

Saving the chat conversation names for later use (list all chats for a user):

"conversations" : {
  "Chris" : {
    "Chris_Nick": true
  },
  "Nick" : {
    "Chris_Nick": true
  }
}

Upvotes: 0

Views: 1371

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317750

To be honest, it's a bad design to put all the messages of a discussion in a single document. Each message should be its own document in a collection. In a general sense, applications should never store growing lists of data in a document without a very well-defined cap to that data.

If you are still concerned about the limit of 1MB per document, the documentation tells you how to compute the size of that document, given that you already know what data will go in it.

Upvotes: 2

Related Questions