title: MongoDB Find by string length
body: <p>I have a collection containing field "MobileNumber". I need to find records with following conditions:</p>
  
  <p>1- start with 9613 and number of characters different than 10<br>
  2- start with 961 and not 9613 and number of characters different than 11 </p>
  
  <p>Collection looks like this:</p>
  
  <pre><code>[
   {"_id": ObjectId("..."), "MobileNumber": "961xxxx", "Name" : "John"},
   {"_id": ObjectId("..."), "MobileNumber": "961xxxx", "Name" : "Alex"},
   {"_id": ObjectId("..."), "MobileNumber": "971xxxx", "Name" : "Fatima"},
   {"_id": ObjectId("..."), "MobileNumber": "971xxxx", "Name" : "Mughees"},
   {"_id": ObjectId("..."), "MobileNumber": "901xxxx", "Name" : "Mike"},
   {"_id": ObjectId("..."), "MobileNumber": "911xxxx", "Name" : "Thomas"}
  ]
  </code></pre>
  
  <p>I tried like this:</p>
  
  <pre><code>db.mobileinfos.find(
  { 
     $expr: { 
          $and:[ 
               {MobileNumber: /^961/},
               {$ne: [{ $strLenCP: "$MobileNumber" }, 10 ] }
             ]    
  } 
  }
  )
  </code></pre>
  
  <p>But it looks like above query ignored first condition of $and and gave records for only second condition.</p>
  
  <p>I am getting all mobile numbers whose length not equal to 10. But i need only those mobile numbers start with 961 and length is not equal to 10.
  Kindly advice.</p>