모듈: 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 = {}) ⇒ 결과
컬렉션 에서 문서를 제거합니다.
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 285 286 287 288 289 290 291 292 293 294 295 296 |
# 파일 'lib/ Mongo/ 컬렉션/view/writable.rb', 줄 257 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) ) nro_write_with_retry(write_concern, 컨텍스트: 컨텍스트) do |연결, txn_num, 컨텍스트| gte_4_4 = 연결.서버.description.server_version_gte?('4.4') 만약 !gte_4_4 && opts[:hint] && write_concern && !write_concern.인정? 올리다 오류::UnsupportedOption.hint_error(unacknowledged_write: true) end 작업::삭제.신규( 삭제합니다: [ 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], ).execution_with_connection(연결, 컨텍스트: 컨텍스트) end end end |
#delete_one(opts = {}) ⇒ 결과
컬렉션 에서 문서 를 제거합니다.
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 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
# 파일 'lib/ Mongo/ 컬렉션/view/writable.rb', 줄 323 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, 컨텍스트| gte_4_4 = 연결.서버.description.server_version_gte?('4.4') 만약 !gte_4_4 && opts[:hint] && write_concern && !write_concern.인정? 올리다 오류::UnsupportedOption.hint_error(unacknowledged_write: true) end 작업::삭제.신규( 삭제합니다: [ 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를 통해 데이터베이스에서 단일 문서를 찾아 삭제하고 원본 문서를 반환합니다.
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 101 102 103 104 105 106 107 108 |
# 파일 'lib/ Mongo/ 컬렉션/view/writable.rb', 줄 64 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, 컨텍스트| gte_4_4 = 연결.서버.description.server_version_gte?('4.4') 만약 !gte_4_4 && opts[:hint] && write_concern && !write_concern.인정? 올리다 오류::UnsupportedOption.hint_error(unacknowledged_write: true) end 작업::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
하나의 문서를 찾아서 대체합니다.
140 141 142 |
# 파일 'lib/ Mongo/ 컬렉션/view/writable.rb', 줄 140 def find_one_and_replace(교체, opts = {}) find_one_and_update(교체, opts) end |
#find_one_and_update(document, opts = {}) ⇒ BSON::Document | nil
단일 문서를 찾아서 업데이트합니다.
업데이트 가 적용 되어야 합니다.
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 221 222 223 224 225 226 227 228 229 230 |
# 파일 'lib/ Mongo/ 컬렉션/view/writable.rb', 줄 182 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) ) write_with_retry(write_concern, 컨텍스트: 컨텍스트) do |연결, txn_num, 컨텍스트| gte_4_4 = 연결.서버.description.server_version_gte?('4.4') 만약 !gte_4_4 && opts[:hint] && write_concern && !write_concern.인정? 올리다 오류::UnsupportedOption.hint_error(unacknowledged_write: true) end 작업::WriteCommand.신규( 선택기: cmd, db_name: database.이름, write_concern: write_concern, 세션: Session, txn_num: txn_num, ).execution_with_connection(연결, 컨텍스트: 컨텍스트) end end.first&.가져오기('value', nil) value 하지 않는 한 value.nil? || value.비어 있나요? end |
#replace_one(replacement, opts = {}) ⇒ 결과
데이터베이스 의 단일 문서 를 새 문서 로 바꿉니다.
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 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 |
# 파일 'lib/ Mongo/ 컬렉션/view/writable.rb', 줄 396 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['데이터 정렬'] || 데이터 정렬, }.컴팩트 만약 opts[: 업서트] update_doc['upsert'] = true end 컨텍스트 = 작업::Context.신규( 클라이언트: 고객, 세션: Session, operation_timeout: operation_timeout(opts) ) write_with_retry(write_concern, 컨텍스트: 컨텍스트) do |연결, txn_num, 컨텍스트| gte_4_2 = 연결.서버.description.server_version_gte?('4.2') 만약 !gte_4_2 && opts[:hint] && write_concern && !write_concern.인정? 올리다 오류::UnsupportedOption.hint_error(unacknowledged_write: true) end 작업::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 = {}) ⇒ 결과
컬렉션 의 문서를 업데이트합니다.
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 |
# 파일 'lib/ Mongo/ 컬렉션/view/writable.rb', 줄 476 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['데이터 정렬'] || 데이터 정렬, }.컴팩트 만약 opts[: 업서트] update_doc['upsert'] = true end 컨텍스트 = 작업::Context.신규( 클라이언트: 고객, 세션: Session, operation_timeout: operation_timeout(opts) ) nro_write_with_retry(write_concern, 컨텍스트: 컨텍스트) do |연결, txn_num, 컨텍스트| gte_4_2 = 연결.서버.description.server_version_gte?('4.2') 만약 !gte_4_2 && opts[:hint] && write_concern && !write_concern.인정? 올리다 오류::UnsupportedOption.hint_error(unacknowledged_write: true) end 작업::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 = {}) ⇒ 결과
컬렉션 에서 단일 문서 를 업데이트합니다.
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 |
# 파일 'lib/ Mongo/ 컬렉션/view/writable.rb', 줄 556 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['데이터 정렬'] || 데이터 정렬, }.컴팩트 만약 opts[: 업서트] update_doc['upsert'] = true end 컨텍스트 = 작업::Context.신규( 클라이언트: 고객, 세션: Session, operation_timeout: operation_timeout(opts) ) write_with_retry(write_concern, 컨텍스트: 컨텍스트) do |연결, txn_num, 컨텍스트| gte_4_2 = 연결.서버.description.server_version_gte?('4.2') 만약 !gte_4_2 && opts[:hint] && write_concern && !write_concern.인정? 올리다 오류::UnsupportedOption.hint_error(unacknowledged_write: true) end 작업::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 |