When users add links to the Mongo Collection, I aim to retrieve the most popular ones based on the frequency of a particular link in the collection. For predefined data like the number of links from YouTube, you can use the following:
Meteor.users.find({ "site": "youtube" }).count()
However, how do you handle dynamic data, for example, such as these specific links:
Meteor.users.find({ "url": "youtube.com/watch?v=u1z4vkPWkLQ" }).count()
UPDATE:
How can this be displayed on the client side? When attempting the code below, an error appears in the console indicating that Videos.aggregate is not recognized as a function.
Template.frontPage.helpers({
mostDownloadedVideos: function() {
return Videos.aggregate(
[ { $unwind : "$filename"},
{ $group : { _id : "$filename", number : { $sum : 1} } },
{ $sort : {number : -1} },
{ $limit : 3 }
]
);
}
});