module MongoModel::DocumentExtensions::CollectionModifiers::ClassMethods

Public Instance Methods

add_to_set!(args) click to toggle source

Post.add_to_set!(:tags => 'xxx')

# File lib/mongomodel/document/collection_modifiers.rb, line 50
def add_to_set!(args)
  collection_modifier_update('$addToSet', args)
end
increase!(args)
Alias for: increment!
increment!(args) click to toggle source

Post.increment!(:hits => 1, :available => -1) This method is also aliased as increase!

# File lib/mongomodel/document/collection_modifiers.rb, line 23
def increment!(args)
  collection_modifier_update('$inc', args)
end
Also aliased as: increase!
pop!(*args) click to toggle source

Post.pop!(:tags)

# File lib/mongomodel/document/collection_modifiers.rb, line 65
def pop!(*args)
  values = args.each_with_object({}) { |key, hash| hash[key.to_s] = 1 }
  collection_modifier_update('$pop', values)
end
pull!(args) click to toggle source

Post.pull!(:tags => 'xxx')

# File lib/mongomodel/document/collection_modifiers.rb, line 55
def pull!(args)
  collection_modifier_update('$pull', args)
end
pull_all!(args) click to toggle source

Post.pull_all!(:tags => ['xxx', 'yyy', 'zzz'])

# File lib/mongomodel/document/collection_modifiers.rb, line 60
def pull_all!(args)
  collection_modifier_update('$pullAll', args)
end
push!(args) click to toggle source

Post.push!(:tags => 'xxx')

# File lib/mongomodel/document/collection_modifiers.rb, line 40
def push!(args)
  collection_modifier_update('$push', args)
end
push_all!(args) click to toggle source

Post.push_all!(:tags => ['xxx', 'yyy', 'zzz'])

# File lib/mongomodel/document/collection_modifiers.rb, line 45
def push_all!(args)
  collection_modifier_update('$pushAll', args)
end
rename!(args) click to toggle source

requires mongodb 1.7.2 Post.rename!(:tags => :tag_collection)

# File lib/mongomodel/document/collection_modifiers.rb, line 78
def rename!(args)
  collection_modifier_update('$rename', args)
end
set!(args) click to toggle source

Post.set!(:hits => 0, :available => 100)

# File lib/mongomodel/document/collection_modifiers.rb, line 29
def set!(args)
  collection_modifier_update('$set', args)
end
shift!(*args) click to toggle source

Post.shift!(:tags, :data)

# File lib/mongomodel/document/collection_modifiers.rb, line 71
def shift!(*args)
  values = args.each_with_object({}) { |key, hash| hash[key.to_s] = -1 }
  collection_modifier_update('$pop', values)
end
unset!(*args) click to toggle source

Post.unset!(:hits, :available)

# File lib/mongomodel/document/collection_modifiers.rb, line 34
def unset!(*args)
  values = args.each_with_object({}) { |key, hash| hash[key.to_s] = 1 }
  collection_modifier_update('$unset', values)
end

Private Instance Methods

collection_modifier_update(modifier, args) click to toggle source
# File lib/mongomodel/document/collection_modifiers.rb, line 83
def collection_modifier_update(modifier, args)
  selector = MongoModel::MongoOptions.new(self, scoped.finder_options).selector
  collection.update(selector, { modifier => args.stringify_keys! }, :multi => true)
end