title: MongoID relational queries
body: <p>I had these models</p>
  
  <pre><code>class State
    include Mongoid::Document
    field :name    
    embeds_many :cities
  end
  
  
  class City
    include Mongoid::Document    
    field :name
    field :zip_code    
    embedded_in :state    
    references_many :organization_addresses
  end
  
  class Organization
    include Mongoid::Document    
    field :name    
    references_many :organization_addresses
  end
  
  class OrganizationAddress
    include Mongoid::Document    
    field :address
    field :latitude, :type=&gt;Float
    field :longitude, :type=&gt;Float    
    referenced_in :organization
    referenced_in :city
  end
  </code></pre>
  
  <p>Now i want to create an address for an organization and reference that address to a city whose zip_code is  <code>06511</code>. First thing how can i find city which is embedded in state. and then how i can i reference it. I wrote query <code>State.where("cities.zip_code"=&gt;"06511").count</code> It do not return any thing where as the city is there in the database. </p>
  
  <p>How can i search it and then reference it to the address of the organization?</p>