Home > Back-end >  how to send a list of popular and hot ranking books from back end using only one query in mongodb
how to send a list of popular and hot ranking books from back end using only one query in mongodb

Time:07-31

Consider Schema for records:

title: String,
author_name: String,
pub_date: Date,
rating: Number,
ratingCount: Number

Now, I have route path /books which sends list of popular and hot ranking book to the front end and I am calculating score for popular books using bayson avg and for hot ranking some other algo.

I am thinking of computing score at the time of sending but the problem is I want to do all of it in one mongodb query(compute two of type of score and sort one list according to one and other list on another). I have tried using aggregate and it seems perfect fit for my requirement but I haven't been able to form two separate list.

CodePudding user response:

You can use something like in following link this for expected results.

Facet

  • Related