Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
102 lines (60 sloc) 2.47 KB


Inspired by mbleigh's "acts_as_taggable_on," this tagging plugin works with MongoDB+MongoMapper.

Intends to be super-performant by taking advantage of the benefits of document-driven db denormalization.


  • MongoDB
  • MongoMapper gem
  • Expects you to have a User model that includes MongoMapper::Document


Best practice -- install the gem:

gem install acts_as_mongo_taggable

… and add a line to your environment.rb:

config.gem 'acts_as_mongo_taggable'

or, if you're old-school, install as a plugin:

./script/plugin install git://

Finally, add this line to the Rails model class that you want to make taggable:

include ActsAsMongoTaggable

Yeah, that's it.


class User
  include MongoMapper::Document

class Widget
  include MongoMapper::Document
  include ActsAsMongoTaggable

To rate it:

widget.tag(word_or_words, user)
  • word_or_words can be a string, a string of comma-delimited words, or an array
  • user is the User who is tagging this widget

Basic search:


... will return the first Widget object that has been tagged with that phrase


... will return an array of Widget objects, all of which have been tagged with that phrase


... will return the Widget object that has been tagged the most times with that phrase

Making tag clouds:


... will return a nice array of arrays, a la [["rails", 8],["ruby", 12], ["php", 6], ["java", 2]] Use this to make yourself a tag cloud for now. (maybe I'll implement a tag cloud view helper someday.)

Statistics on Tags:


... returns the top 25 most used tags across all taggable object classes in the system


... returns the top 25 most used tags for Widget objects


  • Performance improvements as I come across the need

Thanks To...

  • Jon Bell for some sweet refactorings and gem-ification
  • John Nunemaker and the rest of the folks on the MongoMapper Google Group
  • Kyle Banker and his excellent blog posts on grouping and aggregation
  • The MongoDB peoples and the MongoDB Google Group
  • mbleigh for the acts_as_taggable_on plugin for ActiveRecord

Copyright (c) 2009 [M. E. Patterson], released under the MIT license

Jump to Line
Something went wrong with that request. Please try again.