title: Ruby on Rails + MongoDB and MongoID
body: <p>I have created a sample DB with MongoDB with data from a JSON file on mongodbs website
  I have imported it with the following command.
  mongoimport --db test --collection zips --file zips.json
  The data is being processed and when I try to search for data in the console it will show up, so far so good.</p>
  
  <p>My problem is when I'm trying to use the DB with my Rails app. I have created a Class, City, the code looks like this.</p>
  
  <pre><code>    class City
         include Mongoid::Document
         field :c, as: :city, type: String
         field :l, as: :loc, type: Array
         field :p, as: :population, type: Integer
         field :s, as: :state, type: String
         field :_id, type: Integer
      end
  </code></pre>
  
  <p>And my mongoid.yml file looks like this</p>
  
  <pre><code>    development:
       # Configure available database sessions. (required)
      sessions:
       # Defines the default session. (required)
      default:
       # Defines the name of the default database that Mongoid can connect to.
       # (required).
      database: exjobb
       # Provides the hosts the default session can connect to. Must be an array
       # of host:port pairs. (required)
      hosts:
        - localhost:27017
      options:
  
      options:
  
      test:
       sessions:
        default:
         database: exjobb
         hosts:
          - localhost:27017
         options:
         consistency: :strong
          # In the test environment we lower the retries and retry interval to
          # low amounts for fast failures.
          max_retries: 1
          retry_interval: 0
  </code></pre>
  
  <p>Activerecord is disabled. When Im starting rails console and try City.where...
  I get the following output.</p>
  
  <pre><code>    City.where(city: "Acmar")
      =&gt; #&lt;Mongoid::Criteria
      selector: {"c"=&gt;"Acmar"}
      options:  {}
      class:    City
      embedded: false&gt;
  </code></pre>
  
  <p>And if I try City.first an error is thrown</p>
  
  <pre><code>    NoMethodError: undefined method `to_sym' for nil:NilClass
  from /Users/admin/.rvm/gems/ruby-1.9.3-p374/gems/mongoid-3.1.2/lib/mongoid/sessions.rb:409:in `__evaluate__'
  from /Users/admin/.rvm/gems/ruby-1.9.3-p374/gems/mongoid-3.1.2/lib/mongoid/sessions.rb:357:in `__database_name__'
  from /Users/admin/.rvm/gems/ruby-1.9.3-p374/gems/mongoid-3.1.2/lib/mongoid/sessions.rb:198:in `database_name'
  from /Users/admin/.rvm/gems/ruby-1.9.3-p374/gems/mongoid-3.1.2/lib/mongoid/sessions.rb:429:in `current_database_name'
  from /Users/admin/.rvm/gems/ruby-1.9.3-p374/gems/mongoid-3.1.2/lib/mongoid/sessions.rb:228:in `mongo_session'
  from /Users/admin/.rvm/gems/ruby-1.9.3-p374/gems/mongoid-3.1.2/lib/mongoid/sessions.rb:171:in `collection'
  from /Users/admin/.rvm/gems/ruby-1.9.3-p374/gems/mongoid-3.1.2/lib/mongoid/contextual/mongo.rb:256:in `initialize'
  from /Users/admin/.rvm/gems/ruby-1.9.3-p374/gems/mongoid-3.1.2/lib/mongoid/contextual.rb:48:in `new'
  from /Users/admin/.rvm/gems/ruby-1.9.3-p374/gems/mongoid-3.1.2/lib/mongoid/contextual.rb:48:in `create_context'
  from /Users/admin/.rvm/gems/ruby-1.9.3-p374/gems/mongoid-3.1.2/lib/mongoid/contextual.rb:31:in `context'
  from /Users/admin/.rvm/gems/ruby-1.9.3-p374/gems/mongoid-3.1.2/lib/mongoid/contextual.rb:21:in `rescue in first'
  from /Users/admin/.rvm/gems/ruby-1.9.3-p374/gems/mongoid-3.1.2/lib/mongoid/contextual.rb:19:in `first'
  from /Users/admin/.rvm/gems/ruby-1.9.3-p374/gems/mongoid-3.1.2/lib/mongoid/finders.rb:117:in `first'
  from (irb):1
  from /Users/admin/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.11/lib/rails/commands/console.rb:47:in `start'
  from /Users/admin/.rvm/gems/ruby-1.9.3-p374/gems/railties-3.2.11/lib/rails/commands/console.rb:8:in `start'
  from /Users/admin/.rvm/gems/ruby-1.9.3-p374/gems/railties-    3.2.11/lib/rails/commands.rb:41:in `&lt;top (required)&gt;'
  from script/rails:6:in `require'
  </code></pre>
  
  <p>I've uploaded my code <a href="https://github.com/josefottosson/exjobb" rel="nofollow">here</a>, please clone and try to help me, im stuck.
  As you can see, my db is not empty. <a href="http://i.stack.imgur.com/Bho2H.png" rel="nofollow">http://i.stack.imgur.com/Bho2H.png</a></p>