I
I
IDONTSUDO2020-03-20 15:20:59
MongoDB
IDONTSUDO, 2020-03-20 15:20:59

How to design Mongo or SQL database for correspondence?

there are users, these users have personal correspondence.
The table/document of correspondence looks something like this.

Chanel:{
uuid:
name:
any:
users:
}

These tables have messages
Table/Document messages
Chanel:{
uuid:
chanel_id:
any:
user:
}

Problems begin at the stage when you need to somehow distinguish between those messages that the user has read and those that have not been read. Let's say we start duplicating data. We take users by type and generate a message for each user, and then everything is simple and clear in the sense of what exactly is read and what is not. Problems begin with editing / deleting a message. As it turns out, let's say we have a chat for 100 people. And if one of them edits the message, you need to change / delete all other messages.

Method 2.
Add a structure to the channel label.

usersRead:[{
user:uuid,
num:Number
}]


And it seems to solve the problem with a thousand documents. But we are beginning to depend on the front. We have to control the socket connection on two levels.

1. Whether the user is viewing these messages right now.
2. Whether the user is online.
And we start some kind of nonsense with calculations on the back, because we need to constantly sort through some kind of document / table. / Of course, we can do all this at the level of the fact that we just JOIN them all these plates. And we do not have calculations, but then the load falls on the database.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question