I have a collection with schema (mongoose) say :
{
name : String,
age : Number,
params : [Number] // e.g. : params = [1,21,45,32,0] , usually they are very small arrays
}
The collection has 1000s of documents of this type
Say, I have a baseParams = [1,20,30,4,7];
I want to use aggregation and find the id of document whose params contain most number of numbers in baseParams array, like max(for each doc intersection(baseParams,params))
I finally need the _id of top 5 document sorted by age : 1
Any ideas anyone ?