Nested array query using mongoose
<p>I'm using mongoose (with nodejs) to make my queries.</p>

<p>I got the following Schemas for my database model (minified ofc):</p>

<pre><code>var HistorySchema = new Schema({ 
    status  :   String,
    time    :   Date
});

var TaskSchema   = new Schema({
    game_id             : Schema.Types.ObjectId,    
    history             : [HistorySchema]
}, {collection: 'task'});
</code></pre>

<p>Now I want to give an example (insertion) for this which I want to use to show my problem and wish:
(Insertion)</p>

<pre><code>{
    "_id" : ObjectId("5772ca87439632101510fa6b"),
    "history" : 
    [
        {
            "status" : "open",
            "time" : ISODate("2016-06-25T12:17:46.982Z")
        },
        {
            "status" : "complete",
            "time" : ISODate("2016-06-30T12:17:46.982Z")
        }
    ]
}
</code></pre>

<p>so far so good... Now I have a given date, in this case:</p>

<pre><code>ISODate("2016-06-28T12:17:46.982Z")
</code></pre>

<p>Now I want to get from my collection all TaskSchema objects including matching HistorySchmea objects from the array. So I want to exclude the not matching part in history array.</p>

<p>I tried many things like $pull operation like</p>

<pre><code>db.task.find(
{
    "game_id": ObjectId("57711397893a97aa170aa983"),
    "history.time":{
        $lte: ISODate("2016-06-28T12:17:46.982Z")
    }
},{$pull: {
    "history": {
        time: {
            $gte: ISODate("2016-06-28T12:17:46.982Z")
        }
    }
  }
}
</code></pre>

<p>but then I get errors like</p>

<pre><code>Unsupported projection option: $pull: { history: { time: { $gte: new Date(1467116266982) } } }
</code></pre>

<p>Does anyone know how I could realize this query? I'm working now for days on this and couldn't find any help.</p>

<p>Thanks in advance!</p>