Saturday 29 April 2017

Mongoose find all posts and get the hottest categories

i have this problem where i need to find the hottest categories from all the posts that i've search.

This is my POST schema model

var PostSchema = new mongoose.Schema({
    maincategory: String,
    subcategory: String,
    quantity: String,
    budget: Number,
    name: String,
    description: String,
});


PostSchema.index({name: 'text', description: 'text'});

So what i need to do is, crawl to all the posts, check their main category and sub category, then after crawling to all posts and get their categories, i need to count on how many posts on this categories then sort out the categories where i will show the categories which has the highest amount of posts. Then i will show which categories are the hottest, maybe top 5

Thank you!



via John

No comments:

Post a Comment