MongoDB: Getting document and only one object of an array
<p>I got multiple documents like this:</p>

<pre><code>{
    "_id" : "sgG6G9XTvvjj7uxwQ",
    "title" : "A title",
    "notes" : [
        {
            "id" : "ePce6fBAHx9KeKjuM",
            "timestamp" : 1453731403807,
            "message" : "some text",
            "name" : "Tom"
        },
        {
            "id" : "BAHx9KeKjuMePce6f",
            "timestamp" : 1453731403808,
            "message" : "some text",
            "name" : "Bob"
        },
        {
            "id" : "ePce6fBAHx9KeKjuM",
            "timestamp" : 1453731403809,
            "message" : "some text",
            "name" : "Tom"
        }
    ]
}
</code></pre>

<p>I get this document by using this <code>find</code>-query:</p>

<pre><code>Collection.find({}, { sort: { title: 1 }});
</code></pre>

<p>But I don't need the complete <code>notes</code> field. I'm only interested in the <code>id</code> of the last note-object. That means I have to order all notes object by timestamp and just take the first (=newest) one.</p>

<p>I'm not quite sure, if I can do that by the <code>find</code>-query or if I have to do that after getting the complete data.</p>

<p>So the best result for me would be:</p>

<pre><code>{
    "_id" : "sgG6G9XTvvjj7uxwQ",
    "title" : "A title",
    "notes" : [
        {
            "id" : "ePce6fBAHx9KeKjuM"
        }
    ]
}
</code></pre>