모듈: Mongoid::Contextual::Atomic

다음에 정의됨:
lib/mongoid/contextual/atomic.rb

개요

Mixin module included in Mongoid::Criteria which provides a direct method interface to MongoDB's Update Operators ($set, $pull, $inc, etc.) These operators can be applied to update all documents in the database within the criteria scope, without loading each document into Mongoid's memory.

인스턴스 메서드 요약 접기

인스턴스 메서드 세부 정보

#add_each_to_set(추가) ⇒ nil

일치하는 문서에 대해 원자적 $addToSet/$each를 수행합니다.

예시:

세트에 값을 추가합니다.

context.add_each_to_set(members: ["Dave", "Bill"], genres: ["Electro", "Disco"])

매개변수:

  • 추가합니다. (해시)

    작업.

반환합니다:

  • (nil)

    Nil.



31
32
33
# 파일 'lib/mongoid/contextual/atomic.rb', 줄 31

def add_each_to_set(추가합니다.)
  보기.update_many('$addToSet' => collection_each_operations(추가합니다.))
end

#add_to_set(adds) ⇒ nil

일치하는 문서에서 원자적 $addToSet를 실행합니다.

예시:

세트에 값을 추가합니다.

context.add_to_set(members: "Dave", genres: "Electro")

매개변수:

  • 추가합니다. (해시)

    작업.

반환합니다:

  • (nil)

    Nil.



19
20
21
# 파일 'lib/mongoid/contextual/atomic.rb', 줄 19

def add_to_set(추가합니다.)
  보기.update_many('$addToSet' => collection_operations(추가합니다.))
end

#bit(bits) ⇒ nil

일치하는 문서에 대해 원자적 $bit 작업을 수행합니다.

예시:

비트 연산을 수행합니다.

context.bit(likes: { and: 14, or: 4 })

매개변수:

  • 비트 (해시)

    작업.

반환합니다:

  • (nil)

    Nil.



43
44
45
# 파일 'lib/mongoid/contextual/atomic.rb', 줄 43

def 비트(비트)
  보기.update_many('$bit' => collection_operations(비트))
end

#inc(incs) ⇒ nil

일치하는 문서에 대해 원자적 $inc 작업을 수행합니다.

예시:

원자 증분을 수행합니다.

context.inc(likes: 10)

매개변수:

  • incs (해시)

    작업.

반환합니다:

  • (nil)

    Nil.



55
56
57
# 파일 'lib/mongoid/contextual/atomic.rb', 줄 55

def Inc(incs)
  보기.update_many('$inc' => collection_operations(incs))
end

#mul(인자) ⇒ nil

일치하는 문서에 대해 원자적 $mul 연산을 수행합니다.

예시:

원자적 곱셈을 수행합니다.

context.mul(likes: 10)

매개변수:

  • 요인 (해시)

    작업.

반환합니다:

  • (nil)

    Nil.



67
68
69
# 파일 'lib/mongoid/contextual/atomic.rb', 줄 67

def mul(요인)
  보기.update_many('$mul' => collection_operations(요인))
end

#팝업(pops) ⇒ nil

일치하는 문서에 대해 원자적 $pop 작업을 수행합니다.

예시:

일치하는 항목에서 첫 번째 값을 팝합니다.

context.pop(members: -1)

일치 항목의 마지막 값을 표시합니다.

context.pop(members: 1)

매개변수:

  • (해시)

    작업.

반환합니다:

  • (nil)

    Nil.



82
83
84
# 파일 'lib/mongoid/contextual/atomic.rb', 줄 82

def ()
  보기.update_many('$pop' => collection_operations())
end

#pull(pull) ⇒ nil

참고:

표현식 풀링은 아직 지원되지 않습니다.

일치하는 문서에 대해 원자적 $pull 작업을 수행합니다.

예시:

일치 항목에서 값을 가져옵니다.

context.pull(members: "Dave")

매개변수:

  • pulls (해시)

    작업.

반환합니다:

  • (nil)

    Nil.



96
97
98
# 파일 'lib/mongoid/contextual/atomic.rb', 줄 96

def pull(pulls)
  보기.update_many('$pull' => collection_operations(pulls))
end

#pull_all(pulls) ⇒ nil

일치하는 문서에 대해 원자적 $pullAll 작업을 수행합니다.

예시:

일치 항목에서 일치하는 모든 값을 가져옵니다.

context.pull_all(:members, [ "Alan", "Vince" ])

매개변수:

  • pulls (해시)

    작업.

반환합니다:

  • (nil)

    Nil.



108
109
110
# 파일 'lib/mongoid/contextual/atomic.rb', 줄 108

def pull_all(pulls)
  보기.update_many('$pullAll' => collection_operations(pulls))
end

#push(푸시) ⇒ nil

일치하는 문서에 대해 원자적 $push 작업을 수행합니다.

예시:

일치하는 Docs 에 값을 푸시합니다.

context.push(members: "Alan")

매개변수:

  • 푸시 (해시)

    작업.

반환합니다:

  • (nil)

    Nil.



120
121
122
# 파일 'lib/mongoid/contextual/atomic.rb', 줄 120

def push(푸시)
  보기.update_many('$push' => collection_operations(푸시))
end

#push_all(푸시) ⇒ nil

일치하는 문서에 대해 원자적 $push/$each 작업을 수행합니다.

예시:

일치하는 Docs 에 값을 푸시합니다.

context.push_all(members: [ "Alan", "Fletch" ])

매개변수:

  • 푸시 (해시)

    작업.

반환합니다:

  • (nil)

    Nil.



132
133
134
# 파일 'lib/mongoid/contextual/atomic.rb', 줄 132

def push_all(푸시)
  보기.update_many('$push' => collection_each_operations(푸시))
end

#rename(renames) ⇒ nil

일치하는 문서에서 필드의 원자적 $rename을 수행합니다.

예시:

일치하는 문서에서 필드 이름을 변경합니다.

context.rename(members: :artists)

매개변수:

  • rename (해시)

    작업.

반환합니다:

  • (nil)

    Nil.



144
145
146
147
148
149
# 파일 'lib/mongoid/contextual/atomic.rb', 줄 144

def 이름 변경(rename)
  연산 = rename.each_with_object({}) do |(old_name, new_name), ops|
    ops[old_name] = new_name.to_s
  end
  보기.update_many('$rename' => collection_operations(연산))
end

#set(sets) ⇒ nil

일치하는 문서에서 원자적 $set의 필드를 수행합니다.

예시:

일치 항목에 필드 값을 설정합니다.

context.set(name: "Depeche Mode")

매개변수:

  • 집합 (Sets) (해시)

    작업.

반환합니다:

  • (nil)

    Nil.



159
160
161
# 파일 'lib/mongoid/contextual/atomic.rb', 줄 159

def 세트(집합 (Sets))
  보기.update_many('$set' => collection_operations(집합 (Sets)))
end

#set_max(fields) ⇒ nil ~ 라고도 함: camp_lower_bound

참고:

Mongoid::Contextual::Aggregable::Mongo#max가 있기 때문에 이 메서드의 이름을 #max로 지정할 수 없으며, 이는 다른 유사한 메서드에서 수행하는 MongoDB 작업의 이름 지정 규칙을 위반합니다.

지정된 필드 에 대해 원자적 $max 업데이트 작업을 수행합니다. 각 필드 는 [current_value, 주어진 값]의 최대값으로 설정하다 됩니다. 이렇게 하면 각 필드 가 지정된 값보다 작지 않은지 확인하는 효과가 있습니다. 즉, 지정된 값은 해당 필드 의 유효 최소값 입니다.

예시:

Set "views" to be no less than 100.

context.set_max(views: 100)

매개변수:

  • 필드 (해시)

    각각 설정하다 수 있는 최소값이 있는 필드입니다.

반환합니다:

  • (nil)

    Nil.



219
220
221
# 파일 'lib/mongoid/contextual/atomic.rb', 줄 219

def set_max(필드)
  보기.update_many('$max' => collection_operations(필드))
end

#set_min(fields) ⇒ nil ~ 라고도 함: camp_upper_bound

참고:

Mongoid::Contextual::Aggregable::Mongo#min이 있기 때문에 이 메서드의 이름을 #min으로 지정할 수 없으며, 따라서 이 메서드가 수행하는 MongoDB 작업에 따라 이름을 지정하는 관행을 깨는 것입니다.

지정된 필드 에 대해 원자적 $min 업데이트 작업을 수행합니다. 각 필드 는 [current_value, 주어진 값]의 최소값으로 설정하다 됩니다. 이렇게 하면 각 필드 가 지정된 값보다 크지 않은지 확인하는 효과가 있습니다. 즉, 지정된 값은 해당 필드 의 유효 최대 값입니다.

예시:

Set "views" to be no more than 100.

context.set_min(views: 100)

매개변수:

  • 필드 (해시)

    각각 설정하다 수 있는 최대값이 있는 필드입니다.

반환합니다:

  • (nil)

    Nil.



196
197
198
# 파일 'lib/mongoid/contextual/atomic.rb', 줄 196

def set_min(필드)
  보기.update_many('$min' => collection_operations(필드))
end

#unset(*unsets) ⇒ nil

일치하는 문서에서 필드의 원자적 $unset을 수행합니다.

예시:

일치 항목에서 필드 설정을 해제합니다.

context.unset(:name)

매개변수:

  • *unsets ([ string | 기호 | 배열<string | 기호> | 해시 ]...)

    설정 해제할 필드 의 이름입니다. 해시를 지정하면 값이 nil 또는 false인 경우에도 값에 관계없이 해당 키가 사용됩니다.

반환합니다:

  • (nil)

    Nil.



174
175
176
# 파일 'lib/mongoid/contextual/atomic.rb', 줄 174

def Unset(*Unsets)
  보기.update_many('$unset' => collection_unset_operations(Unsets))
end