I have written a query that looks like it should work but I can't figure out why it doesn't.
Firstly - I narrowed down a query to make sure it was actually working. the line with $expr in it proves that the fields are correct ( i.e. the same results show with or without it ) .
db.nzpostRecon.find(
{ $and: [
{"eship.order.packages.0.tracking_number":"AB41045027010225"},
{"ticketNumber":"AB41045027010225"},
{$expr: { $eq: ["$this.eship.order.packages.0.tracking_number", "$this.ticketNumber"] }},
{"eship.order.packages.0.tracking_number" : {$exists: true}}
]
However, when I remove the first 2 lines, the results don't make sense. When I run it I get some documents that have a value in the tracking_number field ( in the array ) - but the ticketNumber field is blank - so they are definitely not equal even though both fields exist. I'm baffled by this & think maybe my understanding of that part of the query is wrong.
db.nzpostRecon.find(
{ $and: [
{$expr: { $eq: ["$this.eship.order.packages.0.tracking_number", "$this.ticketNumber"] }},
{"eship.order.packages.0.tracking_number" : {$exists: true}}
]
$exprallows aggregation expression operators within the find query.