'Anonymous "likes/reactions" using Firebase

Question from junior Padawan to real Jedy.

I'm developing a website for a designer portfolio. Without any registration and backend. I'm using Firebase instead. I need to add a feature to collect "likes" (reactions) from anonymous users on works/posts.

Firebase RTDB structure:

+artworks:
  +someArtWorkID1: 
     name: "lorem ipsum"
     description: "lorem ipsum"
     date: "01.01.1970"
     src: "here should be url to picture"
     **likes**: (?)

Idk how to implement it. Should it be a simple number or array of UIDs (anonymous user ID)?

Or another structure:

 +artworks...
 +likes:
   +idOfArtwork:
     uid: true,
     uid2: true
     ..........

But in that case, how can I calculate the sum of "likes" for specific post/artwork?

Also, I am new to Firebase and haven't any ideas how to write rules for it. In order for the anonymous user could add/delete only his UID in the likes array. Or should I use another solution for this task? Help me please)



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source