Currently, I have used a very simple approach that works very well: just enable the Array field.
#app/models/image.rb class Image include Mongoid::Document include Mongoid::Timestamps field :message, :type => String field :tags, :type => Array def self.images_for tag Image.any_in(:tags => [tag]) end end #routes.rb match "tag/:tag" => "images#tag" #/app/controller/images_controller.rb class ImagesController < ApplicationController # GET /tag # GET /tag.xml def tag @images = Image.images_for params[:tag] respond_to do |format| format.html { render "index" } format.xml { render :xml => @images } end end end
This works, but I still have little doubt about the performance of Image.any_in map / reduce. I think that there may be a better solution for this card / reduction, but not yet found.
berkes
source share