I'm trying to write an aggregation query with $expr inside $lookup's $match pipeline stage. I found some problems related to the array dot notation.
Imagine a collection relations with the array field called nodes.
The following query works fine returning correct results:
db.relations.find({"nodes.0": { "type" : "User", "id" : UUID("dc20f7c7-bd45-4fc1-9eb4-3604428fa551") }})
But the one below returns nothing:
db.relations.find({$expr: {$and: [ {$eq: ["$nodes.0", { "type" : "User", "id" : UUID("dc20f7c7-bd45-4fc1-9eb4-3604428fa551") }]}]}})
To me they seem to be effectively the same, and I don't understand why the results differ.
I tried to use the $arrayElemAt operator, it works, but unfortunately it triggers the COLLSCAN execution plan, which is undesirable, as I have an index on nodes.0.
I didn't find anything special about $eq operator in the docs, they even explicitly mention that those two expression forms are equivalent.