How to organize huskies blog posts (express/mongoose)?

There is a scheme post and user. As I understand need for flexibility to create a schema like and write there user id / post id.
But I don't understand how can I provide a handler. the nonsense goes ...


Ie collections likes need to find the record with the post id && id user,
if the record already exists, then delete it and reduce the count of likes from the post,
if the entry does not exist, create it and increase the count of likes from the post.
But how to catch the promise from the condition ? Please explain
( async/ await do not offer, I want to understand how it should work,
and then make async/ await consciously )
June 5th 19 at 21:30
1 answer
June 5th 19 at 21:32
I would do the collection Likes refused if they do not need to do complex Analytics and just would have made from the post field with the Likes array with the id of polzovateley or who liked their references to objects from the collection of users. And if you want to keep the chronology that would add a collection of Events to record the events of the "likno"
On the one hand it is a simple option. But then you have to cut the array from the issuance of not to pull it where it is not needed, but still have user can have its own array podpischikov working on the same lines. Yet it is not quite flexibly if you need to display all the posts which user like. Although I'm ready to select this option because you don't know how to do. - modesta_McLaughlin commented on June 5th 19 at 21:35
the sample on the field containing the array is real. If you still need a binders collection, use the patern waterflow for requests in the first check, the second add/delete. There are already ready libraries for the realization of the pattern. But again, I think a link collection in this particular task is superfluous, after all, not a relational database. It would be necessary if in addition to when you need to store some more info - Orville_Hop commented on June 5th 19 at 21:38

Find more questions by tags Express.jsMongooseNode.js