I have following structure in documentdb
{
"_id": {
"$oid": "5bc7a1d14cedfd0006445b10"
},
"externalId": {
"$numberLong": "70285"
},
"passengers": [
{
"_id": {
"$numberLong": "3757"
},
"name": "abc",
"email": "[email protected]"
},
{
"_id": {
"$numberLong": "398"
},
"name": "abc n",
"email": "[email protected]"
}
]
}
I was trying to find documents where first two element in array have same email
Now with mongo db the following query works (answered here )
db.collection.find({
$expr: {
$eq: [
{
$arrayElemAt: [
"$passengers.email",
0
]
},
{
$arrayElemAt: [
"$passengers.email",
1
]
}
]
}
})
However this does not work with DocumentDb. The document db engine version is 5.0
Is there an alternative query in documentDb for the same?
I think I have a solution for you, using
$letwhich is supported in DocumentDB and allows for evaluation operators. Is not as straightforward as using $expr, but it does the job: