I'm building a quite fancy "trending" posts algorithm using MongoDB. As the algorithm consumes quite a lot of time, I'm executing my algorithm in a cron task and then I cache a sorted array of posts ids. Like this (PHP vardump):
"trending" => array("548ac5ce05ea675e468b4966", "5469c6d5039069a5030041a7", ...)
The point is that I can not find any way to retrieve them in that order using MongoDB. Using MySQL it would be done just by doing:
SELECT * FROM posts
ORDER BY FIELD(_id, '548ac5ce05ea675e468b4966', '5469c6d5039069a5030041a7',...)
What I tried so far is what it can be founde here, so now I am able to retrieve an sorted list with the weight, but not the posts. The response is like this:
{
"result" : [
{
"_id" : ObjectId("548ac5ce05ea675e468b4966"),
"weight" : 1
},
{
"_id" : ObjectId("5469c6d5039069a5030041a7"),
"weight" : 2
}
],
"ok" : 1
}
Does anyone has achieved this or even know where to start?
Thank you!