title: mongoose remove an object from a nested array
body: <p>I am trying to find an update a document using mongoose, by removing an object from a nested array. My target document is the following:</p>
  
  <pre><code>user = {
      "userId" : "myId",
      "connections":
      [{
          "dateConnectedUnix": 1334567891,
          "isActive": true,
          "sessions": [
              {"device": "mobile", "country": "US"},
              {"device": "desktop", "country": "US"}
          ]
      }, {
          "dateConnectedUnix": 1334567893,
          "isActive": false,
          "sessions": [
              {"device": "mobile", "country": "CA"},
              {"device": "desktop", "country": "CA"}
          ]
      }]
  }
  </code></pre>
  
  <p>here is my attempt, but it is not updating the document:</p>
  
  <pre><code>Users.findOneAndUpdate({ "userId": "myId", "connections.dateConnectedUnix": 1334567891 },
      { $pull: { sessions: { device: "mobile" } } }, (err) =&gt; {
          if (err) {
              return res.status(404).json({ message: 'Error' });
          }
          return res.status(200).json({
              success: true,
              message: 'success'
          });
      }
  );
  </code></pre>
  
  <p>the resulting document should look like:</p>
  
  <pre><code>user = {
      "userId" : "myId",
      "connections":
      [{
          "dateConnectedUnix": 1334567891,
          "isActive": true,
          "sessions": [
              {"device": "desktop", "country": "US"}
          ]
      }, {
          "dateConnectedUnix": 1334567893,
          "isActive": false,
          "sessions": [
              {"device": "mobile", "country": "CA"},
              {"device": "desktop", "country": "CA"}
          ]
      }]
  }
  </code></pre>
  
  <p>basically it is finding the user by the id, and then finding the connection by date, and then removing the device if mobile. In my particular case, the result is always one matching document and one matching connection and one matching session.</p>