I have an array idsToHunt
- this contains x number of IDs.
I'm using this is an aggregate like:
Question.aggregate([
{$match: {publicID: { $in: idsToHunt} },
{$project: {_id:0, publicID:1, score:1} },
{$sort: {score: -1}}
],
function(err, found) {
nextStep = found
resolve();
})
Now where I have {$sort: {score: -1}}
- what i really want to do is sort by the index of idsToHunt
.
So if idsToHunt = ['da22', 'ye66', '17hy']
Then I'd like the projected results to be like:
{publicID: 'da22', score: '2'}, {publicID: 'ye66', score: '2'}, {publicID: '17hy', score: '2'}
rather than a random order as it is now:
{publicID: 'da22', score: '2'}, {publicID: '17hy', score: '2'}, {publicID: 'ye66', score: '2'}
Hope that makes sense - any help would be appreciated.
Thanks.