title: Array validation on a field at collection creation on Mongodb using PHP
body: <p>I've got a little problem using MongoDB 3.2, PHP 5.6.16 with the PHPDriver mongod 1.1 and the 'official' MongoDB PHPLIB</p>
  
  <p>I want to create a collection with a validator:</p>
  
  <pre><code>createCollection('client',[
  'validator' =&gt; [
    'total' =&gt; ['$type' =&gt; 'int'],
    'Appliref' =&gt; ['$type'=&gt; 'array'],
  ],
  ]);
  </code></pre>
  
  <p>If I do like presented, Mongo will check on insertion that my document contains 
  'total' which is an Int;
  And 'Appliref' which contains an array </p>
  
  <p>( ! It will not check if Appliref is an array only if it contains an array:</p>
  
  <p>For example :</p>
  
  <pre><code>insertOne([
    'total'=&gt;55,
    'Appliref'=&gt;array('1224','4447')]; will not be ok
  insertOne([
    'total'=&gt;55,
    'Appliref'=&gt;array('1224',array('1111','2222'))]; will be ok )
  </code></pre>
  
  <p>The explanation is in the documentation of <a href="https://docs.mongodb.com/manual/reference/operator/query/type/" rel="nofollow noreferrer">$type</a> </p>
  
  <p>but my goal is, of course, to validate both, more specifically to check if Appliref is an array or not.</p>
  
  <p>I found a solution on an other Website :</p>
  
  <pre><code>db.createCollection("user" , { validator : { "hoge.0" : {$exists : true}}})
  </code></pre>
  
  <p>the idea is to check if the first element of the array exists;</p>
  
  <p>I can't find a way to do it in PHP using the => and I not sure it's the perfect solution</p>
  
  <p>If someone got a solution ( for a PHP use please :( ) or a way to use the solution I found in PHP that would be great,</p>
  
  <p>Sorry for bad English, if there is.</p>