title: Mongodb: read documents/arrays and delete them immediately
body: <p><strong>Technical Background:</strong> I'm using tokumx (support <a href="http://docs.tokutek.com/tokumx/tokumx-concurrency.html#tokumx-concurrency-document-level-locks" rel="nofollow">document level locking</a>) and php.</p>
  
  <p>The document structure is like this</p>
  
  <pre><code>{
    "accounts": [
      {
        "username": "1",
      },
      {
        "username": "2",
      }
    ],
    "site": "test.com"
  }
  </code></pre>
  
  <p><strong>Situation:</strong></p>
  
  <p>Most of the time, I only need <strong>first x accounts</strong> from "accounts" array.</p>
  
  <p>The minutes <strong>these first x accounts</strong> are retrieved, they should be deleted from the "accounts" array in the document.</p>
  
  <p><strong>Compromise I can make:</strong></p>
  
  <p>extract out "accounts".</p>
  
  <pre><code>  {
      "username" : "1",
      "site": "test.com"
    },
  
    {
      "username" : "2",
      "site": "test.com"
    }
  </code></pre>
  
  <p>Or switch to MySql (last option).</p>
  
  <hr>