Reputation: 1995
In document there is date element like doj:20100223
in YYYYMMDD format. I am looking for the query which display all records where doj>2010. Below i have tried but didn't work.
db.TestData1.aggregate(
{ $project : {name : 1 }},
{ $match : { doj : { $gt : 2010}}}
)
Any suggestion..
Thanks
Upvotes: 0
Views: 221
Reputation: 4288
Since your data appears to be stored in an integer field, your query should look like :
db.TestData1.aggregate(
{ $match : { doj : { $gt : 20109999}}},
{ $project : {name : 1 }}
)
Beware the $project
operator reshapes every record, so you need to either include the doj field you want to query here, or move it after the $match
in the pipeline.
Upvotes: 2