How to query by highest number of matches in mongoose

Viewed 12

I have this documents where inside they have an array of ids Example:

{
 name: Bryan,
 products: [
   product: id: 1,
   product: id: 2,
   product: id: 3,
]
}

{
 name: Mike,
 products: [
   product: id: 1,
   product: id: 3,
   product: id: 4,
]
}

And i need to pass an array of ids, but i need to obtain the result with highest coincidence

Example, i send this array:

{
 products: [
   product: id: 1,
   product: id: 2,
   product: id: 5,
]
}

and returns to me

{
 name: Bryan,
 products: [
   product: id: 1,
   product: id: 2,
   product: id: 3,
]
}
0 Answers
Related