Skip to content

Instantly share code, notes, and snippets.

@akeem
Created June 16, 2010 19:03
Show Gist options
  • Save akeem/441119 to your computer and use it in GitHub Desktop.
Save akeem/441119 to your computer and use it in GitHub Desktop.
#$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
require 'mongo_mapper'
require 'pp'
class NedFlanders
def initialize
MongoMapper.database = 'testing'
end
end
#x = NedFlanders.new #if you specify the database prior to scope method declaration things seem to work well.
class User
include MongoMapper::Document
# plain old vanilla scopes with fancy queries
scope :johns, where(:name => 'John')
key :name, String
key :tags, Array
end
x = NedFlanders.new
User.collection.remove # empties collection
User.create(:name => 'John', :tags => %w[ruby mongo])
# simple scopes
pp User.johns.first
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment