I have the following document structure in Mongo:
{
"participantIdentities": [
{
"player": {
"summonerName": "Summ1",
"otherData": "Whatever"
},
"participantId": 1
},
{
"player": {
"summonerName": "Summ2",
"otherData": "Whatever2"
},
"participantId": 2
}
]
}
And I am trying to return the index of one of the elements, so I can then pass that to the next part of the pipeline but it's throwing an error.
Code:
db.match.aggregate(
[
{
"$project": {
"matchedIndex": {
"$indexOfArray": [
"$participantIdentities", {"$player.summonerName": {$eq: "Summ2"}}
]
}
}
}
]
)
Error:
"ok" : 0,
"errmsg" : "Unrecognized expression '$participantIdentities.player.summonerName'",
"code" : 168,
"codeName" : "InvalidPipelineOperator"
I'm not sure what I'm doing wrong, I'm not sure if querying the current array's elements is supported which might be the issue?
In the example above, I'd want it to return the second element's array index (where summonerName is Summ2) i.e. {"matchedIndex": 1}. What am I doing wrong?