MongoDB - The Best Way to Store and Read Data

I have a Mongo database.

I have two collections:

  • of users
  • posts

The user sends a message, but the question is here. Which way is better?

  • Save only user _id per post (POST CREATOR).
  • Keep user information like (_id, name, username, ...) behind the message.

In the first method, we need to get user information from the USERS collection.

In the second method, we need to update all the message data that was sent by the user Only when the user updated the profile information.

What's better?

+4
source share
4 answers

MongoDB.

.

+3

MongoDB. , , :

1- ,

2-, ( )

+4

, :

a) nr () ? (, )

b) nr ? (, )

c) ()?

- MongoDB. nr nr , , , . , , mongodb .

# 1, , . , .

№2, , , , . . , , . , , , , ( _id), , .

, , , , , - # 2 .

.

+4

, , .

, , , .

, .

+2

Source: https://habr.com/ru/post/1664851/


All Articles