Hi, I’m using ReactiveAggregate. I could make the new collection and use it in the client side. What I coded is to take every word in the title of an article and then map it to all the articles that has that word in their title. Now what I want is to sort by count (descending) and limit the number of documents in the collection to 5. (I want the top 5 documents order by count).
var reg1 = new RegExp("^[A-Za-záàâãéèêíïóôõöúçñÁÀÂÃÉÈÍÏÓÔÕÖÚÇÑ0-9]{1}$", "g");
var reg2 = new RegExp("^[A-Za-záàâãéèêíïóôõöúçñÁÀÂÃÉÈÍÏÓÔÕÖÚÇÑ0-9]{2}$", "g");
var reg3 = new RegExp("^[A-Za-záàâãéèêíïóôõöúçñÁÀÂÃÉÈÍÏÓÔÕÖÚÇÑ0-9]{3}$", "g");
Meteor.publish("topics", function () {
ReactiveAggregate(this, Articles, [
{
$project: {
topic: { $split: ["$title", " "] },
date_seconds: 1,
documento: "$$ROOT"
}
},
{
$unwind: {
path: "$topic"
}
},
{
$match: {
topic: { $nin: ["sports", reg1, reg2,reg3] },
date_seconds: { $gte: timestamp }
}
},
{
$group: {
_id: "$topic",
count: { $sum: 1 },
articles: { $push: "$documento" },
}
}
], { clientCollection: "clientTopic" });
});