0
我在Mongoid下面的文檔結構:SQL到MongoDB的使用Rails + Mongoid
class Post
include Mongoid::Document
field "title", type: String
field "body", type: String
field "category_name", type: String
field "category_id", type: Integer
end
,我需要選擇職位的所有現有類別進行搜索。如果這是SQL,我會:
SELECT distinct category_name, category_id FROM posts
我怎麼會在Mongoid的SQL查詢中做到這一點?