M
M
Mark Berezovsky2020-12-07 16:28:13
JSON
Mark Berezovsky, 2020-12-07 16:28:13

How to save user's messages with date in database?

So I ran into this dilemma:
I have users and they send messages. The message comes to the server, and it would seem that I just need to save it in some general list (log). But here the question arises: how can I save messages so that I can get a list of messages of a certain time interval ?
You answer: save them with a unix timestamp, and then just go through the entire list. But here another problem arises: how can I save messages so that I can get a list of messages from a specific user of a certain time interval ?
Please offer your ideas for data organization. What is the best way to save messages in each user, or save them in the general list? If I save them both there and there, then it will take up a lot of memory. I also need to get a general list of all messages .

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Rsa97, 2020-12-07
@Rsa97

So what's the problem then?
`messages` (`user_id`, `timestamp`, `text`)

D
Developer, 2020-12-07
@samodum

Each message has three required fields - userId, timestamp and the text itself.
Everything.
What is the problem?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question