I have a collection with the following document :
{
"observation": {
"temporalExtent": [
{
"dateBeg": ISODate("2002-07-28T20:47:00.000+02:00"),
"dateEnd": ISODate("2003-09-13T16:17:00.000+02:00")
}
]
}
}
I'm trying to make the following aggregation operation that should return the document above but I can't figure out what's wrong and why the document is not found.
db.collection.aggregate({
"$match": {
"observation.temporalExtent": {
"$elemMatch": {
"dateBeg": {
"$gte": {
"$dateFromString": {
"dateString": "1892-01-05T23:50:39.000Z"
}
}
}
}
}
}
})
Any idea? You can play with this config here
Edit
The aggregation operation $dateFromString
is generated by Spring-data-mongodb DateOperators.DateFromString fromString(Object value) method. I'd like to know why I'm misusing this operator or another way to generate the same operation with $date
or ISODate
constructor as mentionned by @arsendavtyan and @mani.
Criteria.where("dateBeg")
.lte(DateOperators.DateFromString.fromString(tmpExtent.getString("fromDate")))
.lte(DateOperators.DateFromString.fromString(tmpExtent.getString("toDate")))