Note that there are some explanatory texts on larger screens.

plurals
  1. POmongoid query rails 3
    primarykey
    data
    text
    <p>brand new to MongoDB / mongoid and still pretty green on ruby / rails</p> <p>on the rails console:</p> <pre><code>t = Task.all(:conditions =&gt; {:title =&gt; "task2"}) =&gt; #&lt;Mongoid::Criteria selector: {:title=&gt;"task2"}, options: {}, class: Task, embedded: false&gt; &gt;&gt; t.first =&gt; #&lt;Task _id: 4d7e2cdb73ec3227dd000009, title: "task2", latitude: 23.987904829, longitude: -12.9423875, created_by: "4d792d6973ec3248e3000001"&gt; </code></pre> <p>returns what I would expect, but</p> <pre><code>t = Task.where(:created_by =&gt; "4d792d6973ec3248e3000001") =&gt; #&lt;Mongoid::Criteria selector: {:created_by=&gt;BSON::ObjectId('4d792d6973ec3248e3000001')}, options: {}, class: Task, embedded: false&gt; &gt;&gt; t.first =&gt; nil </code></pre> <p>same result with:</p> <pre><code>t = Task.all(:conditions =&gt; {:created_by =&gt; "4d792d6973ec3248e3000001"}) </code></pre> <p>here is the model:</p> <pre><code>class Task include Mongoid::Document field :title field :latitude, :type =&gt; Float field :longitude, :type =&gt; Float field :created_by end </code></pre> <p>what am I doing wrong ?</p> <p>updated example:</p> <pre><code>&gt;&gt; Task.new(:title =&gt; "task8", :created_by =&gt; "4d792d6973ec3248e3000001") =&gt; #&lt;Task _id: 4d81037973ec32cc22000003, latitude: nil, longitude: nil, title: "task8", created_by: "4d792d6973ec3248e3000001"&gt; &gt;&gt; t = Task.all(:conditions =&gt; {:created_by =&gt; "4d792d6973ec3248e3000001"}) =&gt; #&lt;Mongoid::Criteria selector: {:created_by=&gt;BSON::ObjectId('4d792d6973ec3248e3000001')}, options: {}, class: Task, embedded: false&gt; &gt;&gt; t.first =&gt; nil </code></pre> <p>do I need to specifically define created_by as :type => String ?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload