Answer the question
In order to leave comments, you need to log in
Do I understand mongo database design correctly?
I want to clarify the questions. previously used SQL there are collections users and events = [{name:"",date:""
,
user_id:""}] output, for example, a list of
events
[{name:"",date:"",user_id:"",username:"",email}]
When a user changes his data, I go through all the events and change the corresponding field
will add reviews - mongo's idea is to put [{name:"",date:"",user_id:"",username:"",email:"", events: [{....},{ ... }] }] instead of separate as it would look in SQL???? how problematic and resource-intensive it will be after, for example, to display a list of 10 recent reviews
Answer the question
In order to leave comments, you need to log in
you are trying to cram a relational model into a document-oriented monga.
user_id shouldn't exist at all.
In general, the easiest way, imagine a normal relational database, then imagine the queries with joins that you want to use. The result of this request is your collection. The records in the tablets have been updated - the collection has been rebuilt from scratch.
The collection in this case will be an aggregation of data, a kind of cache. You can keep several collections, as in the case of relational databases, and form part of the collections dynamically via map / reduce when the data changes. How to optimize the update of this selection is your task as a programmer.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question