ruby on rails - mongoid or condition returning no results -


i using mongoid any_of query find lead appointment status_selected of "option1" or lead source_selected of "opt4". have lead document fits criteria:

> db.leads.find() { "_id" : objectid("556e4f576d61638512060000"), "appointment status_selected" : "option1", "lead source_selected" : "opt2", "updated_at" : isodate("2015-06-03t00:50:31.029z"), "created_at" : isodate("2015-06-03t00:50:31.029z") } 

however, when query using mongoid query helpers, no results:

lead.where({"appointment status_selected" => "option1"}).any_of({"lead source_selected" => "opt4" }).first # => nil 

this moped shows:

moped: 127.0.0.1:27017 query database=core_development collection=leads selector={"appointment status_selected"=>"option1", "$or"=>[{"lead source_selected"=>"opt4"}]} flags=[] limit=-1 skip=0 batch_size=nil fields={:_id=>1} runtime: 13.7830ms moped: 127.0.0.1:27017 query database=core_development collection=leads selector={"appointment status_selected"=>"option1", "$or"=>[{"lead source_selected"=>"opt4"}]} flags=[] limit=0 skip=0 batch_size=nil fields=nil runtime: 4.1470ms

why mongoid not returning record in mongodb?

i try this:

lead.any_of({"appointment status_selected" => "option1"}, {"lead source_selected" => "opt4"}).first 

while i'm not familiar mongoid (or more precisely, origin), can read of origin docs on selection, @ least 1 of $or criteria must true row return. since you're providing 1 criterion #any_of call, may #where call.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - Bypass Geo Redirect for specific directories -

php - .htaccess mod_rewrite for dynamic url which has domain names -