I'm trying to get a certain amount of historical data from my documents similar to the SQL's Between clause. I searched for similar questions and managed to find this query but it only returns the first element of the array, so it's not enough:
db.docs.find({ _id: "eraj4983tj3" }, {history: { $elemMatch : {time: {$gt: new ISODate("2016-03-21T20:53:33.662Z") , $lt: new ISODate("2016-03-21T20:54:20.313Z") } } } });
My documents look like this:
{
    "_id": "eraj4983tj3",
    "descr": "somestuff",
    "history": [
        {
            "time": ISODate("2016-03-21T20:52:31.389Z"),
            "value": 103.91
        },
        {
            "time": ISODate("2016-03-21T20:53:33.663Z"),
            "value": 106.91
        },
        {
            "time": ISODate("2016-03-21T20:53:45.179Z"),
            "value": 104.91
        },
        {
            "time": ISODate("2016-03-21T20:54:20.313Z"),
            "value": 105.11
        },
        {
            "time": ISODate("2016-03-21T20:54:53.649Z"),
            "value": 105.41
        },
        {
            "time": ISODate("2016-03-21T20:55:12.998Z"),
            "value": 115.91
        }
    ]
}
And the result of my query should return this:
{
    "_id": "eraj4983tj3",
    "history": [
        {
            "time": ISODate("2016-03-21T20:53:45.179Z"),
            "value": 104.91
        },
        {
            "time": ISODate("2016-03-21T20:54:20.313Z"),
            "value": 105.11
        },
        {
            "time": ISODate("2016-03-21T20:54:53.649Z"),
            "value": 105.41
        }
    ]
}
How should i write my query to achieve this result?
 
     
    