Skip to content

Instantly share code, notes, and snippets.

@dacort
Created January 26, 2010 20:28
Show Gist options
  • Save dacort/287188 to your computer and use it in GitHub Desktop.
Save dacort/287188 to your computer and use it in GitHub Desktop.
MongoMapper.connection = Mongo::Connection.new('localhost')
MongoMapper.database = 'solrtest'
class User
include MongoMapper::Document
has_many :lists
key :twit_id, Integer, :index => true, :unique => true
key :screen_name, String
key :name, String
key :location, String
key :description, String
key :url, String
key :followers_count, Integer
key :friends_count, Integer
key :listed_on, Array
key :listed_on_count, Integer, :default => 0
def self.push_listed_on(twit_id, list)
push_fields = {'listed_on' => {list.name => list.subscriber_count}}
collection.update({
:twit_id => twit_id
}, '$push' => push_fields, '$inc' => {:listed_on_count => 1})
end
end
class List
include MongoMapper::Document
belongs_to :user
key :user_id, ObjectId
key :twitlist_id, Integer, :index => true, :unique => true
key :name, String
key :subscriber_count, Integer, :default => 1
key :member_count, Integer
key :description, String
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment