I'm having a hard time getting back just the document and subdocument I want. Given the following example, I want MyArray.data returned where somedate is greater than 2018-07-09. I've seen a number of examples but none of them seem to work for me. We're using v3.4.
I tried
db.getCollection('TestCol').find({"MyArray.data.somedate": {"$gt": Date("2018-07-09")}})
but nothing is returned.
Here's the document I'm testing with
{
"_id" : ObjectId("5b46770ca6476fde4407a8df"),
"MyArray" : [
{
"data" : {
"somedate" : "2018-07-10 16:34"
}
},
{
"data" : {
"somedate" : "2018-07-09 15:01"
}
}
]
}
Update I also tried:
db.getCollection('TestCol').aggregate([{$match: {"MyArray.data.somedate": {"$gte": Date("2018-07-09")}}}])