Consider following 3 documents (simplified):
{
"name" : "Alex Ham",
"opponents" : [
{
"location" : "west",
"position" : 5
},
{
"location" : "north",
"position" : 7
},
{
"location" : "east",
"position" : 2
}
]
},
{
"name" : "John Flex",
"opponents" : [
{
"location" : "north",
"position" : 9
},
{
"location" : "north",
"position" : 4
},
{
"location" : "south",
"position" : 2
}
]
},
{
"name" : "Adam Will",
"opponents" : [
{
"location" : "east",
"position" : 6
},
{
"location" : "south",
"position" : 8
}
]
}
I need to match documents by item sequence in array opponents
. I'll have integers such as 572, 942, 68, etc. Each digit of the integer represents position
in opponents
array.
For example, for 572, I need to match first document (Alex Ham), because if you look at the opponents
array, the sequence of items and their position
fields are 5, 7, and 2 respectively.
For 942, I've to match the second document (John Flex), and for 68, I've to match the third document (Adam Will), and so on.
Considering to have huge data (a few million documents), and taking performance into consideration, how can I build an aggregation pipeline to match document for above case.