모듈: Mongoid::Association::Embedded::Batchable

다음을 포함합니다.
위치
포함 항목:
EmbedsMany::Proxy
다음에 정의됨:
lib/mongoid/association/embedded/batchable.rb

개요

내장된 문서에서 작업을 배치 으로 실행하기 위한 동작을 포함합니다.

인스턴스 메서드 요약 접기

Positional에 포함된 메서드

#positionally

인스턴스 메서드 세부 정보

#batch_clear(Docs) ⇒ 배열

한 번의 스와이프로 연결에서 모든 Docs 를 지울 수 있습니다.

예시:

모든 Docs 지우기 .

batchable.batch_clear(docs)

매개변수:

  • 참고자료 (Array<Document>)

    삭제할 Docs 입니다.

반환합니다:

  • (배열)

    빈 배열.

[소스 보기]

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# 파일 'lib/mongoid/association/embedded/batchable.rb', 줄 35

def batch_clear(참고자료)
  pre_process_batch_remove(참고자료, : 삭제)
  하지 않는 한 참고자료.비어 있나요?
    컬렉션.찾기(선택기).update_one(
      위치적으로(선택기, "$unset" => { 경로 => true }),
      세션: _session
    )
    # 이렇게 하면 사용자가 설정, 지우기 및 재설정을 수행하는 경우가 해결됩니다.
    # 내장된 문서. 이전에는 내장된 문서 가
    # 이미 'new_record'가 아닌 것으로 표시되어 있으면 다음 위치에 유지되지 않습니다.
    # 두 번째로. 이 변경 사항은 이 문제를 수정하고 이를 유지할 수 있도록 합니다.
    참고자료. { |doc| doc.new_record = true }
    post_process_batch_remove(참고자료, : 삭제)
  end
  _unscoped.지우기
end

#batch_insert(docs) ⇒ Array<Hash>

새 문서를 배치 푸시($each와 함께 $push)로 삽입합니다. 이렇게 하면 모든 콜백이 적절한 시간에 실행 되고 데이터베이스 에 1 요청 만 이루어집니다.

예시:

배치 푸시를 실행합니다.

batchable.batch_insert([ doc_one, doc_two ])

매개변수:

  • 참고자료 (Array<Document>)

    추가할 Docs 입니다.

반환합니다:

  • (Array<Hash>)

    인서트.

[소스 보기]

23
24
25
# 파일 'lib/mongoid/association/embedded/batchable.rb', 줄 23

def batch_insert(참고자료)
  execution_batch_push(참고자료)
end

#batch_remove(Docs, 메서드 = : 삭제) ⇒ 객체

제공된 문서를 $pullAll 또는 $pull로 일괄 제거 합니다.

예시:

문서를 일괄 제거 합니다.

batchable.batch_remove([ doc_one, doc_two ])

매개변수:

  • 참고자료 (Array<Document>)

    제거 Docs 입니다.

  • 메서드 (기호) (기본값: :delete)

    삭제하거나 파기합니다.

[소스 보기]

59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# 파일 'lib/mongoid/association/embedded/batchable.rb', 줄 59

def batch_remove(참고자료, 메서드 = : 삭제)
  # _id 가 nil이면 $pull을 사용하여 다음을 검색하여 삭제 수 없습니다.
  # ID. 따라서 문서와 함께 pullAll을 사용해야 합니다.
  속성 #개.
  제거 = pre_process_batch_remove(참고자료, 메서드)
  pulls, pull_alls = 제거.파티션 { |o| !o["_id"].nil? }

  만약 !_base.지속되었나요?
    post_process_batch_remove(참고자료, 메서드) 하지 않는 한 참고자료.비어 있나요?
    반환 재색인
  end

  만약 !참고자료.비어 있나요?
    만약 !pulls.비어 있나요?
      컬렉션.찾기(선택기).update_one(
        위치적으로(선택기, "$pull" => { 경로 => { "_id" => { "$in" => pulls.뽑다("_id") } } }),
        세션: _session
      )
    end
    만약 !pull_alls.비어 있나요?
      컬렉션.찾기(선택기).update_one(
        위치적으로(선택기, "$pullAll" => { 경로 => pull_alls }),
        세션: _session
      )
    end
    post_process_batch_remove(참고자료, 메서드)
  other
    컬렉션.찾기(선택기).update_one(
      위치적으로(선택기, "$set" => { 경로 => [] }),
      세션: _session
    )
  end
  재색인
end

#batch_replace(Docs) ⇒ Array<Hash>

제공된 문서를 $ 설정하다 으로 일괄 교체합니다.

예시:

문서를 일괄 교체합니다.

batchable.batch_replace([ doc_one, doc_two ])

매개변수:

  • 참고자료 (Array<Document> | Array<Hash>)

    대체할 Docs 입니다.

반환합니다:

  • (Array<Hash>)

    인서트.

[소스 보기]

102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# 파일 'lib/mongoid/association/embedded/batchable.rb', 줄 102

def batch_replace(참고자료)
  만약 참고자료.비어 있나요?
    만약 _assigning? && !비어 있나요?
      _base.delay_atomic_sets.삭제(경로)
      clear_atomic_path_cache
      _base.add_atomic_unset(first)
      target_duplicate = _target.dup
      pre_process_batch_remove(target_duplicate, : 삭제)
      post_process_batch_remove(target_duplicate, : 삭제)
    other
      batch_remove(_target.dup)
    end
  elsif _target != 참고자료
    _base.delay_atomic_sets.삭제(경로) 하지 않는 한 _assigning?
    참고자료 = normalize_docs(참고자료).컴팩트
    _target.지우기 개인정보 정책에 _unscoped.지우기
    _base.delay_atomic_unsets.삭제(경로)
    clear_atomic_path_cache
    삽입 = execution_batch_set(참고자료)
    add_atomic_sets(삽입)
  end
end