Ok, so if you want to compare to a calculated date you want to use $expr operation:
This means you can use all the aggregation options and compare data (similar to if you want to compare two fields within a document against each other in a find).
With the aggregation style query comes the ability to use aggregation variables such as $$NOW:
You’ll want to compare the field in the doc against the current date, with one day taken away then re-formatted to YYYY-MM-DD format:
db.getCollection("Test").explain().find(
{
$expr:{
$eq:[
'$accountingDate',
{
$dateToString:{
date:{
$dateAdd:{
startDate:'$$NOW',
unit:'day',
amount:-1
}
},
format:'%Y-%m-%d'
}
}
]
}
}
)
Something like this, if doing this on a lot of data, obviously create an index…