title: MongoDB: How to find a document by an id inside a nested document
body: <p>Given a collection like this:..</p>
  
  <pre><code>[
    {
      "_id" : ObjectId("5546329a470000850084a621"),
      "name": "Joe",
      "surname": "Smith",
      "accounts": [
        {
          "_id" : ObjectId("5546329a470000850084a655"),
          "default": true,
          "status" : "approved",
          "activationTime" : ISODate("2013-05-03T14:37:15.025Z")
        },
        {
          "_id" : ObjectId("5546329a470000850084a688"),
          "default": true,
          "status" : "approved",
          "activationTime" : ISODate("2014-06-03T14:37:15.025Z")
        }
      ]
    },
    {
      "_id" : ObjectId("9546329a470079850084a622"),
      "name": "Jimmy",
      "surname": "Brown",
      "accounts": [
        {
          "_id" : ObjectId("5546329a470790850084a651"),
          "default": true,
          "status" : "suspended",
          "activationTime" : ISODate("2015-02-03T14:37:15.025Z")
        },
        {
          "_id" : ObjectId("5546329a470019850084a611"),
          "default": true,
          "status" : "approved",
          "activationTime" : ISODate("2015-04-03T14:37:15.025Z")
        }
      ]
    },
  ]
  </code></pre>
  
  <p>... how do I find a document by <code>accounts.N._id</code>? I've tried this...</p>
  
  <pre><code>db.users.find(
    {},
    {
      "accounts": 0, "accounts": {
        "$elemMatch": { "_id" : ObjectId("5546329a470019850084a611"), "default": true }
      }
    }
  )
  </code></pre>
  
  <p>... but it does't work since I get only the <code>_id</code> of all the documents:</p>
  
  <pre><code>{ "_id" : ObjectId("5546329a470000850084a621") }
  { "_id" : ObjectId("9546329a470079850084a622") }
  </code></pre>
  
  <p>Am I missing something?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>The result that I actually need is something like this:</p>
  
  <pre><code>{
    "_id" : ObjectId("9546329a470079850084a622"),
    "name": "Jimmy",
    "surname": "Brown"
  }
  </code></pre>
  
  <p>For instance, I need to find by <code>accounts.N._id</code> but without showing the nested document itself.</p>