ruby on rails - Mongoid finders not working? -


i have set rails3+mongoid application , when open rails console, none of finders seem work - http://d.pr/fnzc

user.all user.find(:all, :conditions => { first_name => "john" }) 

both return:

#<mongoid::criteria   selector: {},   options:  {}> 

am doing wrong?

okay, part of makes mongoid irritating newcomers. people expect methods user.all return array when returns criteria object.

in order provide syntatic sugar of chainable methods , other fancy query mechanisms, mongoid seems use lazy loading type thing.

you can do:

#array index user.all[0]  #first/last user.all.first  #each on things, print out users user.all.each {|u| p u}  #edit, forgot include this, want #this spits out array user.all.to_a 

it makes difficult verify things working newcomers activerecord user.all returns array.


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -