My document looks like:
> db.users.find().pretty()
{
"_id" : ObjectId("52ee0844177c86dc1d000001"),
"profile" : {
"displayName" : "Sydney",
},
"todos" : [
{
"date" : ISODate("2014-02-02T21:47:13.064Z"),
"value" : "#first in the #middle also but twice #middle and the #end",
"tags" : [
"#first",
"#middle",
"#end"
]
},
{
"date" : ISODate("2014-02-05T21:20:30.904Z"),
"value" : "Find mongo query #mongo #work",
"tags" : [
"#mongo",
"#work"
]
}
]
}
I want to query the todo for a date range:
> var start = new Date()
> var end = new Date()
> start.setDate(start.getDate() - 2)
1391544140700
> start
ISODate("2014-02-04T20:02:20.700Z")
> end
ISODate("2014-02-06T20:02:25.828Z")
>db.users.find({todos: {$elemMatch: {date: { $gte: start, $lt: end }}}}, {'todos':1}).pretty()
but the query still returns the two records. I was expecting to get only the last one.