title: mongodb $regex error: unknown operator
body: <p>I'm trying to check the 1st character of a field to not be a-z</p>
  
  <pre><code>db.zips.aggregate( 
   [
  { $group : { city: { $regex: '^[a-z]', $options: 'i' }, n : {$sum:1} } }
   ]
  )
  </code></pre>
  
  <p>Here is a sample doc expected to be found but the query errors with unknown operator '$regex'. MongoDB v2.4.5 is installed:</p>
  
  <pre><code>{"city": "25536", "loc": [-82.076761, 38.087553], "pop": 61, "state": "WV", "_id":   "25536"}
  </code></pre>
  
  <p>Error:</p>
  
  <pre><code>Error: Printing Stack Trace
  at printStackTrace (src/mongo/shell/utils.js:37:15)
  at DBCollection.aggregate (src/mongo/shell/collection.js:897:9)
  at (shell):1:9
  Wed Jul 31 12:14:14.737 JavaScript execution failed: aggregate failed: {
      "errmsg" : "exception: unknown group operator '$regex'",
      "code" : 15952,
      "ok" : 0
  } at src/mongo/shell/collection.js:L898
  </code></pre>
  
  <p>Thanks!</p>
  
  <p>P.S. I tried this also:</p>
  
  <pre><code>db.zips.aggregate( 
  [
  { $project : { city: /^[a-z]/i }}
  ,{ $group : { city : "$city", n : {$sum:1} } }
  ]
  )
  
  Error: Printing Stack Trace
  at printStackTrace (src/mongo/shell/utils.js:37:15)
  at DBCollection.aggregate (src/mongo/shell/collection.js:897:9)
  at (shell):1:9
  Wed Jul 31 12:26:21.531 JavaScript execution failed: aggregate failed: {
      "errmsg" : "exception: disallowed field type RegEx in object expression
  (at 'city')",
      "code" : 15992,
      "ok" : 0
  } at src/mongo/shell/collection.js:L898
  </code></pre>
  
  <p>So appears that the ways I'm trying to use regex is incorrect or in the incorrect places/operations.</p>