如果我有一个如下所示的类,如何将每个实例的姓氏从一个集合中拉出一个数组?
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?
答案 0 :(得分:1)
Person.all.map(&:last_name)
会这样做
答案 1 :(得分:0)
答案 2 :(得分:0)
Person.where(...搜索...)仅。(:姓氏)