I have documents with this structure:
{
"_id" : ObjectId("59936474a955fb3f18db07d5"),
"CD_MATRICULA" : 12,
"DT_FROM" : ISODate("2014-04-04T16:21:37.000-03:00"),
"DT_FROM_ANO" : 2012,
"DT_FROM_MES" : 2,
"DT_FROM_DIA" : 2 }
In this sample, DT_FROM_ANO differ from YEAR(DT_FROM), I need to find docs that have this difference, I try this but dont work:
db.getCollection('TABLESAMPLE').aggregate(
{$project: {
CD_MATRICULA: 1,
DT_FROM: 1,
DT_FROM_ANO: 1,
DT_FROM_MES: 1,
DT_FROM_DIA: 1,
DT_TO: 1,
ANO: {$year: '$DT_FROM'},
MES: {$month: '$DT_FROM'},
DIA: {$dayOfMonth: '$DT_FROM'}
}
},
{$match:
{ DT_FROM_ANO: {$ne: '$ANO'} }
}
);
All documents will return in this case, exist only one that have YEAR differs. What is wrong ??? I need that only docs with difference between in year returns.