Answer the question
In order to leave comments, you need to log in
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?
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
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 questionAsk a Question
731 491 924 answers to any question