Reputation: 5148
If I have a class that looks like below, how to I pull out just the last name from each instance a collection into an array?
class Person
include :Mongoid::Document
field :first_name
field :middle_name
field :last_name
field :email_address
end
Person.all # What do I do after I have the collection?
Upvotes: 0
Views: 72
Reputation: 3143
To return an array from a collection:
Person.where(blah).collect(&:last_name)
Upvotes: 0
Reputation: 364
Person.where(...search...).only(:last_name)
http://mongoid.org/docs/querying/criteria.html#only
Upvotes: 0