Module: MongoModel::DocumentExtensions::CollectionModifiers::ClassMethods

Defined in:
lib/mongomodel/document/collection_modifiers.rb

Instance Method Summary collapse

Instance Method Details

#add_to_set!(args) ⇒ Object

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


50
51
52
# File 'lib/mongomodel/document/collection_modifiers.rb', line 50

def add_to_set!(args)
  collection_modifier_update('$addToSet', args)
end

#increment!(args) ⇒ Object Also known as: increase!

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


23
24
25
# File 'lib/mongomodel/document/collection_modifiers.rb', line 23

def increment!(args)
  collection_modifier_update('$inc', args)
end

#pop!(*args) ⇒ Object

Post.pop!(:tags)


65
66
67
68
# 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) ⇒ Object

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


55
56
57
# File 'lib/mongomodel/document/collection_modifiers.rb', line 55

def pull!(args)
  collection_modifier_update('$pull', args)
end

#pull_all!(args) ⇒ Object

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


60
61
62
# File 'lib/mongomodel/document/collection_modifiers.rb', line 60

def pull_all!(args)
  collection_modifier_update('$pullAll', args)
end

#push!(args) ⇒ Object

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


40
41
42
# File 'lib/mongomodel/document/collection_modifiers.rb', line 40

def push!(args)
  collection_modifier_update('$push', args)
end

#push_all!(args) ⇒ Object

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


45
46
47
# File 'lib/mongomodel/document/collection_modifiers.rb', line 45

def push_all!(args)
  collection_modifier_update('$pushAll', args)
end

#rename!(args) ⇒ Object

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


78
79
80
# File 'lib/mongomodel/document/collection_modifiers.rb', line 78

def rename!(args)
  collection_modifier_update('$rename', args)
end

#set!(args) ⇒ Object

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


29
30
31
# File 'lib/mongomodel/document/collection_modifiers.rb', line 29

def set!(args)
  collection_modifier_update('$set', args)
end

#shift!(*args) ⇒ Object

Post.shift!(:tags, :data)


71
72
73
74
# 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) ⇒ Object

Post.unset!(:hits, :available)


34
35
36
37
# 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