The question is the next one:
Get documents with tags in list, ordered by total number of matches
But they say that is possible using Aggregation Framework,
Using $size and $setIntersection will solve this efficiently, without causing memory multiplication.
tagList = ['shirt', 'cotton', 'black']
db.test_col.aggregate(
{$match: {tags: {$in: ["shirt","cotton","black"]}}},
{$project:
{"title":1,"tags":1},
{$order:
{"$size":
{"$setIntersection": [ tagList, "$tags" ]}},
{$sort:{order:-1}}
);
First we match the documents which have at least one element matching.
Then we project Keys/Columns we need along with a new order key/column. Order is generated by taking the count of intersected elements between 'tags in db' and 'tags from query'.
Then we do a simple sort in descending order. This worked for me. Similar Question answered here