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 クエリでこれを行うにはどうすればよいですか?