title: MongoDB - ReferenceError: startsWithDigit is not defined
body: <p>Im working on a side project for myself and in my URL Shortener I get an error on our stats page (Example: <a href="http://xd6.co/u/ah/stats" rel="nofollow">http://xd6.co/u/ah/stats</a>) which seems to show up only after the link is created for some time/accumulates clicks, then it gets the error message below:</p>
  
  <pre><code>ReferenceError: startsWithDigit is not defined
      at Object.eval [as toVersionString] (eval at makeFunction (/home/xd6/node_modules/mongolian/node_modules/buffalo/lib/bson.js:380:17))
      at Object.eval [as toString] (eval at makeFunction (/home/xd6/node_modules/mongolian/node_modules/buffalo/lib/bson.js:380:17))
      at String (unknown source)
      at Writer._name (/home/xd6/node_modules/mustache/mustache.js:292:35)
      at Writer._escaped (/home/xd6/node_modules/mustache/mustache.js:296:32)
      at renderFunction (/home/xd6/node_modules/mustache/mustache.js:357:28)
      at subRenders.(anonymous function) (/home/xd6/node_modules/mustache/mustache.js:328:18)
      at Writer._section (/home/xd6/node_modules/mustache/mustache.js:240:21)
      at renderFunction (/home/xd6/node_modules/mustache/mustache.js:345:28)
      at Writer._compile.cache.(anonymous function) (/home/xd6/node_modules/mustache/mustache.js:224:16)
      at Writer.render (/home/xd6/node_modules/mustache/mustache.js:204:34)
      at Object.exports.render (/home/xd6/node_modules/mustache/mustache.js:596:20)
  </code></pre>
  
  <p>And when I run mongo in the console and do <code>db.urls.find()</code> I get this in response:</p>
  
  <pre><code>{ "short" : "aa", "long" : "http://xd6.co/Projects/url-shortener", "created" : "2013-01-03 7:11 UTC", "clicks" : 0, "visitors" : [ ], "subscribers" : [ ], "_id" : ObjectId("50e52f2b000000d358000002") }
  { "short" : "ab", "long" : "http://google.com", "created" : "2013-01-06 1:17 UTC", "clicks" : 0, "visitors" : [ ], "subscribers" : [ ], "_id" : ObjectId("50e8d0c2000000d358000003") }
  { "short" : "ac", "long" : "http://xd6.co/u/", "created" : "2013-01-07 5:54 UTC", "clicks" : 0, "visitors" : [ ], "subscribers" : [ ], "_id" : ObjectId("50ea6332000000435b000002") }
  ReferenceError: startsWithDigit is not defined
  </code></pre>
  
  <p>Which shows that it's a mongo error and not something wrong in our code. Also the Mongo in the console is giving out different results then the nodejs program itself. It's not even showing all of the existing documents that do exist, for example "ae" is not existant in the mongo console output, but the nodejs is obviously finding data somewhere for it (<a href="http://xd6.co/u/api/ae/stats" rel="nofollow">http://xd6.co/u/api/ae/stats</a>).</p>
  
  <p>It also seems to only be an issue with the urls collection since the other two collections we have in the database don't return the error.</p>
  
  <p>Before someone comments on possibly using the wrong db/collection to explain where nodejs is finding the other data (using XD6 DB and urls collection):</p>
  
  <pre><code>&gt; show dbs
  XD6 0.0625GB
  local   (empty)
  test    (empty)
  &gt; use XD6
  switched to db XD6
  &gt; show collections
  pages
  posts
  system.indexes
  urls
  </code></pre>