모듈: Mongo::Collection::View::Writable
- 포함 항목:
- Mongo::Collection::View
- 다음에 정의됨:
- lib/ Mongo/ 컬렉션/view/writable.rb
개요
컬렉션 보기에 대한 쓰기 (write) 관련 동작을 정의합니다.
상수 요약 접기
- ARRAY_FILTERS =
배열은 필드 상수를 필터링합니다.
'array_filters'
인스턴스 메서드 요약 접기
-
#delete_many(opts = {}) ⇒ 결과
컬렉션 에서 문서를 제거합니다.
-
#delete_one(opts = {}) ⇒ 결과
컬렉션 에서 문서 를 제거합니다.
-
#find_one_and_delete(opts = {}) ⇒ BSON::Document?
findAndModify를 통해 데이터베이스에서 단일 문서를 찾아 삭제하고 원본 문서를 반환합니다.
-
#find_one_and_replace(replacement, opts = {}) ⇒ BSON::Document
하나의 문서를 찾아서 대체합니다.
-
#find_one_and_update(document, opts = {}) ⇒ BSON::Document | nil
단일 문서를 찾아서 업데이트합니다.
-
#replace_one(replacement, opts = {}) ⇒ 결과
데이터베이스 의 단일 문서 를 새 문서 로 바꿉니다.
-
#update_many(spec, opts = {}) ⇒ 결과
컬렉션 의 문서를 업데이트합니다.
-
#update_one(spec, opts = {}) ⇒ 결과
컬렉션 에서 단일 문서 를 업데이트합니다.
인스턴스 메서드 세부 정보
#delete_many(opts = {}) ⇒ 결과
컬렉션 에서 문서를 제거합니다.
247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 |
# 파일 'lib/ Mongo/ 컬렉션/view/writable.rb', 줄 247 def delete_many(opts = {}) with_session(opts) do |Session| write_concern = 만약 opts[:write_concern] writeConcern.get(opts[:write_concern]) other write_concern_with_session(Session) end 쿼리 캐시.clear_namespace(컬렉션.namespace) delete_doc = { 작업::q => 필터, 작업::LIMIT => 0, hint: opts[:hint], 데이터 정렬: opts[:collation] || opts['데이터 정렬'] || 데이터 정렬, }.컴팩트 컨텍스트 = 작업::Context.신규( 클라이언트: 고객, 세션: Session, operation_timeout: operation_timeout(opts) ) 작업 = 작업::삭제.신규( 삭제합니다: [ delete_doc ], db_name: 컬렉션.database.이름, coll_name: 컬렉션.이름, write_concern: write_concern, bypass_document_validation: !!opts[:bypass_document_validation], 세션: Session, let: opts[:let], comment: opts[:comment] ) 추적 프로그램.trace_operation(작업, 컨텍스트, op_name: 'deleteMany') do nro_write_with_retry(write_concern, 컨텍스트: 컨텍스트) do |연결, _txn_num, 컨텍스트| 작업.execution_with_connection(연결, 컨텍스트: 컨텍스트) end end end end |
#delete_one(opts = {}) ⇒ 결과
컬렉션 에서 문서 를 제거합니다.
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
# 파일 'lib/ Mongo/ 컬렉션/view/writable.rb', 줄 311 def delete_one(opts = {}) with_session(opts) do |Session| write_concern = 만약 opts[:write_concern] writeConcern.get(opts[:write_concern]) other write_concern_with_session(Session) end 쿼리 캐시.clear_namespace(컬렉션.namespace) delete_doc = { 작업::q => 필터, 작업::LIMIT => 1, hint: opts[:hint], 데이터 정렬: opts[:collation] || opts['데이터 정렬'] || 데이터 정렬, }.컴팩트 컨텍스트 = 작업::Context.신규( 클라이언트: 고객, 세션: Session, operation_timeout: operation_timeout(opts) ) write_with_retry(write_concern, 컨텍스트: 컨텍스트) do |연결, txn_num, 컨텍스트| 작업::삭제.신규( 삭제합니다: [ delete_doc ], db_name: 컬렉션.database.이름, coll_name: 컬렉션.이름, write_concern: write_concern, bypass_document_validation: !!opts[:bypass_document_validation], 세션: Session, txn_num: txn_num, let: opts[:let], comment: opts[:comment] ).execution_with_connection(연결, 컨텍스트: 컨텍스트) end end end |
#find_one_and_delete(opts = {}) ⇒ BSON::Document?
findAndModify를 통해 데이터베이스에서 단일 문서를 찾아 삭제하고 원본 문서를 반환합니다.
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 93 94 95 96 97 98 99 100 |
# 파일 'lib/ Mongo/ 컬렉션/view/writable.rb', 줄 61 def find_one_and_delete(opts = {}) with_session(opts) do |Session| write_concern = 만약 opts[:write_concern] writeConcern.get(opts[:write_concern]) other write_concern_with_session(Session) end 쿼리 캐시.clear_namespace(컬렉션.namespace) cmd = { findAndModify: 컬렉션.이름, query: 필터, 제거: true, 필드: 프로젝션, sort: sort, maxTimeMS: max_time_ms, bypassDocumentValidation: opts[:bypass_document_validation], hint: opts[:hint], 데이터 정렬: opts[:collation] || opts['데이터 정렬'] || 데이터 정렬, let: opts[:let], comment: opts[:comment], }.컴팩트 컨텍스트 = 작업::Context.신규( 클라이언트: 고객, 세션: Session, operation_timeout: operation_timeout(opts) ) write_with_retry(write_concern, 컨텍스트: 컨텍스트) do |연결, txn_num, 컨텍스트| 작업::WriteCommand.신규( 선택기: cmd, db_name: database.이름, write_concern: write_concern, 세션: Session, txn_num: txn_num ).execution_with_connection(연결, 컨텍스트: 컨텍스트) end end.first&.가져오기('value', nil) end |
#find_one_and_replace(replacement, opts = {}) ⇒ BSON::Document
하나의 문서를 찾아서 대체합니다.
132 133 134 |
# 파일 'lib/ Mongo/ 컬렉션/view/writable.rb', 줄 132 def find_one_and_replace(교체, opts = {}) find_one_and_update(교체, opts) end |
#find_one_and_update(document, opts = {}) ⇒ BSON::Document | nil
단일 문서를 찾아서 업데이트합니다.
업데이트 가 적용 되어야 합니다.
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# 파일 'lib/ Mongo/ 컬렉션/view/writable.rb', 줄 174 def find_one_and_update(문서, opts = {}) value = with_session(opts) do |Session| write_concern = 만약 opts[:write_concern] writeConcern.get(opts[:write_concern]) other write_concern_with_session(Session) end 쿼리 캐시.clear_namespace(컬렉션.namespace) cmd = { findAndModify: 컬렉션.이름, query: 필터, arrayFilters: opts[:array_filters] || opts['array_filters'], update: 문서, 필드: 프로젝션, sort: sort, new: !!(opts[:return_document] && opts[:return_document] == :after), upsert: opts[: 업서트], maxTimeMS: max_time_ms, bypassDocumentValidation: opts[:bypass_document_validation], hint: opts[:hint], 데이터 정렬: opts[:collation] || opts['데이터 정렬'] || 데이터 정렬, let: opts[:let], comment: opts[:comment] }.컴팩트 컨텍스트 = 작업::Context.신규( 클라이언트: 고객, 세션: Session, operation_timeout: operation_timeout(opts) ) 작업 = 작업::WriteCommand.신규( 선택기: cmd, db_name: database.이름, write_concern: write_concern, 세션: Session ) value = 추적 프로그램.trace_operation(작업, 컨텍스트, op_name: 'findOneAndUpdate') do write_with_retry(write_concern, 컨텍스트: 컨텍스트) do |연결, txn_num, 컨텍스트| 작업.txn_num = txn_num 작업.execution_with_connection(연결, 컨텍스트: 컨텍스트) end end.first&.가져오기('value', nil) value 하지 않는 한 value.nil? || value.비어 있나요? end end |
#replace_one(replacement, opts = {}) ⇒ 결과
데이터베이스 의 단일 문서 를 새 문서 로 바꿉니다.
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
# 파일 'lib/ Mongo/ 컬렉션/view/writable.rb', 줄 384 def replace_one(교체, opts = {}) with_session(opts) do |Session| write_concern = 만약 opts[:write_concern] writeConcern.get(opts[:write_concern]) other write_concern_with_session(Session) end validate_replacement_documents!(교체) 쿼리 캐시.clear_namespace(컬렉션.namespace) update_doc = { 작업::q => 필터, arrayFilters: opts[:array_filters] || opts['array_filters'], 작업::u => 교체, hint: opts[:hint], 데이터 정렬: opts[:collation] || opts['데이터 정렬'] || 데이터 정렬, sort: opts[:sort] || opts['sort'], }.컴팩트 update_doc['upsert'] = true 만약 opts[: 업서트] 컨텍스트 = 작업::Context.신규( 클라이언트: 고객, 세션: Session, operation_timeout: operation_timeout(opts) ) write_with_retry(write_concern, 컨텍스트: 컨텍스트) do |연결, txn_num, 컨텍스트| 작업::Update.신규( updates: [ update_doc ], db_name: 컬렉션.database.이름, coll_name: 컬렉션.이름, write_concern: write_concern, bypass_document_validation: !!opts[:bypass_document_validation], 세션: Session, txn_num: txn_num, let: opts[:let], comment: opts[:comment] ).execution_with_connection(연결, 컨텍스트: 컨텍스트) end end end |
#update_many(spec, opts = {}) ⇒ 결과
컬렉션 의 문서를 업데이트합니다.
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 |
# 파일 'lib/ Mongo/ 컬렉션/view/writable.rb', 줄 458 def update_many(사양, opts = {}) with_session(opts) do |Session| write_concern = 만약 opts[:write_concern] writeConcern.get(opts[:write_concern]) other write_concern_with_session(Session) end validate_update_documents!(사양) 쿼리 캐시.clear_namespace(컬렉션.namespace) update_doc = { 작업::q => 필터, arrayFilters: opts[:array_filters] || opts['array_filters'], 작업::u => 사양, 작업::멀티 => true, hint: opts[:hint], 데이터 정렬: opts[:collation] || opts['데이터 정렬'] || 데이터 정렬, }.컴팩트 update_doc['upsert'] = true 만약 opts[: 업서트] 컨텍스트 = 작업::Context.신규( 클라이언트: 고객, 세션: Session, operation_timeout: operation_timeout(opts) ) nro_write_with_retry(write_concern, 컨텍스트: 컨텍스트) do |연결, _txn_num, 컨텍스트| 작업::Update.신규( updates: [ update_doc ], db_name: 컬렉션.database.이름, coll_name: 컬렉션.이름, write_concern: write_concern, bypass_document_validation: !!opts[:bypass_document_validation], 세션: Session, let: opts[:let], comment: opts[:comment] ).execution_with_connection(연결, 컨텍스트: 컨텍스트) end end end |
#update_one(spec, opts = {}) ⇒ 결과
컬렉션 에서 단일 문서 를 업데이트합니다.
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 |
# 파일 'lib/ Mongo/ 컬렉션/view/writable.rb', 줄 536 def update_one(사양, opts = {}) with_session(opts) do |Session| write_concern = 만약 opts[:write_concern] writeConcern.get(opts[:write_concern]) other write_concern_with_session(Session) end validate_update_documents!(사양) 쿼리 캐시.clear_namespace(컬렉션.namespace) update_doc = { 작업::q => 필터, arrayFilters: opts[:array_filters] || opts['array_filters'], 작업::u => 사양, hint: opts[:hint], 데이터 정렬: opts[:collation] || opts['데이터 정렬'] || 데이터 정렬, sort: opts[:sort] || opts['sort'], }.컴팩트 update_doc['upsert'] = true 만약 opts[: 업서트] 컨텍스트 = 작업::Context.신규( 클라이언트: 고객, 세션: Session, operation_timeout: operation_timeout(opts) ) 작업 = 작업::Update.신규( updates: [ update_doc ], db_name: 컬렉션.database.이름, coll_name: 컬렉션.이름, write_concern: write_concern, bypass_document_validation: !!opts[:bypass_document_validation], 세션: Session, let: opts[:let], comment: opts[:comment] ) 추적 프로그램.trace_operation(작업, 컨텍스트) do write_with_retry(write_concern, 컨텍스트: 컨텍스트) do |연결, txn_num, 컨텍스트| 작업.txn_num = txn_num 작업.execution_with_connection(연결, 컨텍스트: 컨텍스트) end end end end |