S
S
Siple2018-08-07 16:09:12
Node.js
Siple, 2018-08-07 16:09:12

How to correctly add data to mongoose?

There are 3 Schemas (Post, User, Category).
post has user and category
user and category have posts
Is adding post'a correct?
5b6997d7ec216927680900.png
PS It seemed strange in adding to look for user and category to pass the post id

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RidgeA, 2018-08-07
@Siple

If you need to add a post id to the User and Category - I would use findAndUpdate - this will make the search and update one promise.
Is it worth doing this at all - it's more a question of how to get this information, maybe it's enough to save the author's id and category id in the Post ....
For the category - it clearly suggests itself not to save the id of each post in the category, but vice versa - otherwise hands to ensure data consistency when deleting posts.
But these are all assumptions without knowing what the application should do. Perhaps in your case this approach is justified ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question