I have set up a rails3+mongoid application and when I open the rails console, none of the finders seem to work - http://d.pr/FNzC
User.all
User.find(:all, :conditions => { first_name => "John" })
both return:
#<Mongoid::Criteria
selector: {},
options: {}>
Am I doing something wrong?
Okay, so this is part of what makes mongoid irritating for newcomers. People expect methods like User.all to actually return an array when it really just returns the Criteria object.
In order to provide the syntatic sugar of chainable methods and other fancy query mechanisms, Mongoid seems to use a lazy loading type thing.
You can do:
It makes it difficult to quickly verify that things are working for newcomers from ActiveRecord where User.all just returns an array.
Try this: