title: Executing JS on MongoDB when inserting from PHP
body: <p>When using mongo shell I can run something like this:
  </p>
  
  <pre><code>db.sandbox.insert({"line" : db.eval('storedFunction()') })
         or
  db.sandbox.insert({"line" : function() {return 1337} })
  </code></pre>
  
  <p>I was unable to achieve the same effect using php.
  What I wish to do is run something similar to
  </p>
  
  <pre><code>$fnc = "function() {return 123}";
  $col = (new Mongo)-&gt;database-&gt;collection;
  $col-&gt;insert(['col' =&gt; new MongoCode($fnc)]);
  </code></pre>
  
  <p>and find</p>
  
  <pre><code>{
     "_id" : ...., 
     "col" : 123
  } 
  </code></pre>
  
  <p>in the collection. How can I achieve this? Is it even possible?
  <hr />
  If you want even more details I'm trying to imitate autoincrement. This function that I'm writing should retrieve the last used value of incremental field, increment it and return the value thus assigning a unique value to the document that is being inserted.</p>