I have mongo record that looks like this
{
"status": "LIKED", // or NA
"signedUpAt": "mongo date time", //user signed up time
"lastSeenAt": "mongo date time", // last active time
...other_fields
}
I initially filter the data using some filters, at the end i need to return 10 results with following rules
-
Half of the user’s with status=“LIKED” (rounded up) maximum of 5 random records (If any of those users have signed up within the last 24 hrs prioritise those)
-
randomly selected Users who signed up < 72 hrs ago, maximum of 3 records
-
randomly selected Users who logged in within the past 7 days
-
randomly selected Users who logged in within the past 8 to 15 days(first 3 conditions still dint return 10 results)
-
randomly selected Users who logged in within the past 16 to 30 days(first 4 conditions still dint return 10 results)
-
Any other random user(first 5 conditions still dint return 10 results)
I can think of using mongo facets to return 10 results from each of the above category and then in my code select required records as per the rules, but i want to understand is there a better and more performant way to achieve this, because as everyone over stack overflow says my database has huge set of records :).