How to design mongodb user praise function reasonably?

  mongodb, question

Assuming that users praise articles, the praise operation can be cancelled.

The relationship between users and articles should be many-to-many. I looked at the website of mongodbOne-to-many instance, like it inmanyThe party that addedOneThe id of should be more suitable for the relationship that will not change easily once established. However, frequently changing operations such as praise do not seem to be suitable for this form.

Later I thought of two plans.
The first is to add alikeFor example, if you want to make a comment, you have to push the article id tolikeInside, the article id in the array will be deleted directly every time it is deleted.

// User
 {
 username: 'test',
 Like: [123,234,345,456,567,678,789,890]/Article id
 }

The second is to use the traditional RDB method to build a new one.LikeThe collection of, which stores the user id and article id.

// Like
 {
 user_id: 111,
 post_id: 123
 }

Since there is no practical experience, I come here specially to consult. By the way, is there any better way?

The third scheme proposed here is to store in the posts collection an array of _id of the users who praised the article, for example:

// posts
 {
 _id: ObjectID('4e7020cb7cac81af7136236b'),
 users_like_this_post: [
 ObjectID('4e7020cb7cac81af71362361'),
 ObjectID('4e7020cb7cac81af71362362')
 ]
 }

Check the users who praise an article:

post = db.posts.findOne({_id: ObjectID('4e7020cb7cac81af7136236b')});
 console.log(post.users_like_this_post);

Check the number of comments on an article:

post = db.posts.findOne({_id: ObjectID('4e7020cb7cac81af7136236b')});
 console.log(post.users_like_this_post.length);

Check out articles that have praised 100:

posts = db.posts.find({'users_like_this_post.100': {$exists: true}});

Check user’s articles:

posts = db.posts.find({users_like_this_post: user._id});

User praises post:

db.posts.update({_id: post._id}, {$addToSet: {users_like_this_post: user._id}});

User Praises post Cancellation:

db.posts.update({_id: post._id}, {$pull: {users_like_this_post: user._id}});

PS: The above code has not been tested, please refer to the documentation for testing.