So when user “likes” an artwork, I add a value in the artwork_favorites collection.
This collection is easy to querying when I want to know the count of like for an artwork for exemple. Or to know if user already liked an artwork.
But know I want get the top 10 of the most liked artworks.
How to make this request ? I think I need to use publish-composite to get reactive data. But I don’t know the best way to achieve this query.
I would probably maintain a likesCount property on your artworks collection, rather than dive into something like publish-composite. That way you can still keep your queries simple and performant.
Either what @vigorwebsolutions said, or maintain an array of user _ids who have liked it, that way people can’t double like - and you can still track which users liked what.
You could try my Likeable package which is specifically for implementing this functionality. It keeps a count on the parent record automatically, a record of each like and who took the action, and only allows a user to like each parent record once.
No, not at all. Security is tightly controlled through the use of Simple Schema, allow/deny, and collection-hooks. Publications are left in your hands so you can publish as little or as much information as your application requires. Many times you’ll just want to publish the parent and the corresponding like record for the current user if there is one so you can show the user if they liked it or not.
@cstrat if an artwork have 1 billion likes, they are 1 billion user id in the array.
It’wll be a problem with the size of the collection ?
@copleykj with your package, how can I make this query ?
I see that you have a likeCount() function, but how to request mongo to have the top liked artworks ?