How can I use a field that I just added in the $addFields stage to the following $match stage?
This will return no result:
db.getCollection('myCollection').aggregate([
{$addFields: { "test": ISODate("2018-02-15T03:22:21.000Z")}},
{$match: { $or: [{"timestamp":"$test"}]}}
])
This one will return expected result:
db.getCollection('myCollection').aggregate([
{$addFields: { "test": ISODate("2018-02-15T03:22:21.000Z")}},
{$match: { $or: [{"timestamp":ISODate("2018-02-15T03:22:21.000Z")}]}}
])
How comes that the $test is not resolved in the $match stage?
EDIT I finally post myself a solution for mongdb 2.4 thanks to this answer. Solutions are similar but the problem are not expressed the same way