类:Mongo::Client
Overview
客户端是驱动程序的入口点,也是与之交互的主要对象。
常量摘要折叠
- CRUD_OPTIONS =
不影响集群及其子组件行为的选项。
[ :auto_encryption_options, :database, :read, :read_concern, :write, :write_concern, :retry_reads, :max_read_retries, :read_retry_interval, :retry_writes, :max_write_retries, # 当前不能出现在此处的选项: # # :server_selection_timeout # 集群构造函数使用MongoDB Server选择超时来确定 # 在兼容模式下等待初始扫描的时间,但一次 # 集群已初始化,不再使用此超时。 # 不幸的是,服务器选择器读取服务器选择超时 # 集群,此行为是 Cluster#next_primary 所要求的 # 不带参数。 当 next_primary 被删除时,我们可以重新访问 # 使用具有不同服务器选择超时的相同集群对象。 ].冻结
- VALID_OPTIONS =
有效的客户端选项。
[ :app_name, :auth_mech, :auth_mech_properties, :auth_source, :auto_encryption_options, :bg_error_backtrace, :cleanup, :compressors, :direct_connection, :connect, :connect_timeout, :database, :heartbeat_Frequency, :id_generator, :load_balanced, :local_threshold, :logger, :log_prefix, :max_connecting, :max_idle_time, :max_pool_size, :max_read_retries, :max_write_retries, :min_pool_size, :monitoring, :monitoring_io, :password, :platform, :populator_io, :read, :read_concern, :read_retry_interval, :replica_set, :resolv_options, :retry_reads, :retry_writes, :scan, :sdam_proc, :server_api, :server_selection_timeout, :socket_timeout, :srv_max_hosts, :srv_service_name, :ssl, :ssl_ca_cert, :ssl_ca_cert_object, :ssl_ca_cert_string, :ssl_cert, :ssl_cert_object, :ssl_cert_string, :ssl_key, :ssl_key_object, :ssl_key_pass_phrase, :ssl_key_string, :ssl_verify, :ssl_verify_certificate, :ssl_verify_hostname, :ssl_verify_ocsp_endpoint, :timeout_ms, :truncate_logs, : user, :wait_queue_timeout, :wrapping_libraries, :write, :write_concern, :zlib_compression_level, ].冻结
- VALID_COMPRESSORS =
驱动程序支持的压缩算法。
[ mongo::protocol::压缩::zstd, mongo::protocol::压缩::snappy, mongo::protocol::压缩::zlib ].冻结
- VALID_SERVER_API_VERSIONS =
已知的服务器 API 版本。
%w( 1 ).冻结
Loggable中包含的常量
实例属性摘要折叠
-
# cluster ⇒ Mongo::Cluster
只读
集群 客户端的服务器集群。
-
#数据库⇒ Mongo::Database
只读
数据库客户端端正在操作的数据库。
-
# encrypter ⇒ Mongo::Crypt::AutoEncrypter
只读
封装自动加密行为的对象。
-
# options ⇒ 哈希
只读
选项 配置选项。
类方法摘要折叠
-
。 canonicalize_ruby_options (options) ⇒ 对象
private
将指定选项中的身份验证机制属性(如果给定)小写,然后将选项转换为 Options::Redacted 的实例。
实例方法摘要折叠
-
# == (other) ⇒ true, false (又名:#eql?)
确定此客户端是否等同于另一个对象。
-
# [] (collection_name, options = {}) ⇒ Mongo::Collection
获取所提供集合名称的集合对象。
-
# close ⇒ true
关闭所有连接。
-
# close_encrypter ⇒ true
关闭加密器并清理自动加密资源。
- #已关闭? ⇒ 布尔
- # cluster_options ⇒ 对象 private
-
# database_names (filter = {}, opts = {}) ⇒ Array<String>
获取所有数据库的名称。
-
#encrypted_fields_map ⇒ 哈希 | nil
private
如果在创建客户端时提供了加密字段映射哈希,则返回加密字段映射哈希。
-
# get_session (options = {}) ⇒ 会话 | nil
private
如果可能,返回用于操作的会话。
-
#哈希⇒ 整数
获取客户端的哈希值。
-
#initialize (addresses_or_uri, options = nil) ⇒ 客户端
构造函数
实例化一个新的驱动程序客户端。
-
#检查⇒ string
以string形式获取客户端检查结果。
-
# list_databases (过滤 = {}, name_only = false, opts = {}) ⇒ Array<Hash>
获取每个数据库的信息。
-
# list_mongo_databases (过滤 = {}, opts = {}) ⇒ Array<Mongo::Database>
返回 Mongo::Database 对象的列表。
-
# max_read_retries ⇒ 整数
private
获取使用传统读取重试时客户端可以重试读取操作的最大次数。
-
# max_write_retries ⇒ 整数
private
获取使用传统写入重试时客户端可以重试写入操作的最大次数。
-
# read_concern ⇒ 哈希
获取此客户端的读关注(read concern)。
-
# read_preference ⇒ BSON::Document
从传递给客户端的选项中获取读取偏好(read preference)。
-
# read_retry_interval ⇒ 浮点
private
获取使用传统读取重试时读取重试的时间间隔(以秒为单位)。
-
# reconnect ⇒ true
重新连接客户端。
-
# server_selector ⇒ Mongo::ServerSelector
获取服务器选择器。
-
# start_session (options = {}) ⇒ 会话
启动会话。
-
#摘要⇒ string
获取客户端状态摘要。
-
#timeout_ms ⇒ Integer | nil
private
timeout_ms 选项的值(如果设立)。
-
#timeout_sec ⇒ Float | nil
private
timeout_ms 选项的值转换为秒。
-
# update_options (new_options) ⇒ 哈希
private
从 new_options 更新此客户端的选项,从而验证所有选项。
-
# use (name) ⇒ Mongo::Client
创建一个新客户端,配置为使用具有提供名称的数据库,并使用此客户端中配置的其他选项。
-
# watch (pipeline = [], options = {}) ⇒ ChangeStream
从 MongoDB Server 3.6版本开始,聚合框架支持“$changeStream”管道阶段。
-
# with (new_options = nil) ⇒ Mongo::Client
创建一个新客户端,并将传递的选项合并到该客户端的现有选项上。
-
# with_session (options = {}, &block) ⇒ 对象
private
如果可能,创建一个用于操作的会话,并将其生成提供的区块。
-
# write_concern ⇒ Mongo::WriteConcern
获取此客户端的写关注。
Loggable中包含的方法
#log_debug 、 #log_error 、 #log_ Fatal 、 #log_info 、 #log_warn 、 #logger
构造函数详情
#initialize (addresses_or_uri, options = nil) ⇒客户端
实例化一个新的驱动程序客户端。
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 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 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 |
# File 'lib/ Mongo/ 客户端.rb', 第 502 行 def 初始化(Addresses_or_uri, = nil) = ? .dup : {} 已处理 = process_addresses(Addresses_or_uri, ) uri = 已处理[:uri] 地址 = 已处理[:addresses] = 已处理[:options] # 如果 URI 是 SRV URI,请记下这一点,以便我们可以启动 # 如果拓扑结构是分片集群,则 SRV 轮询。 srv_uri = uri if uri.is_a?(URI::SRVProtocol) = self.class.() # 服务器API版本指定为string 。 # 但是,总是以string形式提供数字 1 是非常烦人的, # 因此在此处转换为string类型。 if server_api = [:server_api] if server_api.is_a?(哈希) server_api = 选项::已编辑.new(server_api) if (版本 = server_api[:version]).is_a?(整型) [:server_api] = server_api.合并(merge)(版本: 版本.to_s) end end end # 对 sdam_proc 进行特殊处理,因为它仅在客户端期间使用 # 构建 sdam_proc = .删除(:sdam_proc) # 对于 gssapi service_name,默认选项以哈希形式给出 #(从顶层向下一级)。 = () .每 do |k, v| default_v = [k] if 哈希 === default_v v = default_v.合并(merge)(v) end [k] = v end = .密钥.每 do |k| if [k].nil? .删除(k) end end @options = () =begin WriteConcern 对象支持 if @options[:write_concern].is_a?(WriteConcern::Base) # 缓存实例,以便我们不会不必要地重建它。 @write_concern = @options[:write_concern] @options[:write_concern] = @write_concern.options end =end @options.冻结 (地址, is_srv: uri.is_a?(URI::SRVProtocol)) = @options.dup .删除(:server_api) @database = Database.new(self, @options[:database], ) # 临时设立监控,以便事件订阅 # 在没有集群的情况下进行设置 @monitoring = 监控.new(@options) if sdam_proc sdam_proc.调用(self) end @connect_lock = 互斥锁.new @connect_lock.同步 do @cluster = 集群.new(地址, @monitoring, .合并(merge)(srv_uri: srv_uri)) end 开始 # 取消设置监控,从现在开始将其从集群中删除 remove_instance_variable(' @monitoring ') if @options[:auto_encryption_options] @connect_lock.同步 do build_encrypter end end 救援 开始 @cluster.关闭 救援 => e log_warn("在客户端构造函数的异常处理程序中关闭集群时出错: #{ e . class } : #{ e } ") # 删除此异常,以便引发原始异常 end 提高 end if block_given? 开始 产量(self) 确保 关闭 end end end |
实例属性详细信息
# 集群 ⇒ Mongo::Cluster (readonly)
返回集群客户端的服务器集群。
139 140 141 |
# File 'lib/ Mongo/ 客户端.rb', 第 139 行 def 集群 @cluster end |
#数据库⇒ Mongo::Database (readonly)
返回数据库 客户端正在操作的数据库。
142 143 144 |
# File 'lib/ Mongo/ 客户端.rb', 第 142 行 def database @database end |
# encrypter ⇒ Mongo::Crypt::AutoEncrypter (readonly)
返回 封装自动加密行为的对象。
149 150 151 |
# File 'lib/ Mongo/ 客户端.rb', 第 149 行 def 加密器 @encrypter end |
# options ⇒哈希(只读)
返回 options 配置选项。
145 146 147 |
# File 'lib/ Mongo/ 客户端.rb', 第 145 行 def @options end |
类方法详细信息
。 canonicalize_ruby_options (options) ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
将指定选项中的身份验证机制属性(如果给定)小写,然后将选项转换为 Options::Redacted 的实例。
1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 |
# File 'lib/ Mongo/ 客户端.rb', 第 1162 行 def () 选项::已编辑.new(哈希[.map do |k, v| if k == :auth_mech_properties || k == ' auth_mech_properties ' if v v = 哈希[v.map { |pk, pv| [pk.Downcase, pv] }] end end [k, v] end]) end |
实例方法详细信息
# == (other) ⇒ true , false也称为: eql?
确定此客户端是否等同于另一个对象。
178 179 180 181 |
# File 'lib/ Mongo/ 客户端.rb', 第 178 行 def ==(其他) return false 除非 其他.is_a?(客户) 集群 == 其他.集群 && == 其他. end |
# [] (collection_name, options = {}) ⇒ Mongo::Collection
获取所提供集合名称的集合对象。
195 196 197 |
# File 'lib/ Mongo/ 客户端.rb', 第 195 行 def [ ](collection_name, = {}) database[collection_name, ] end |
# close ⇒ true
关闭所有连接。
865 866 867 868 869 870 871 |
# File 'lib/ Mongo/ 客户端.rb', 第 865 行 def 关闭 @connect_lock.同步 do @close = true do_close end true end |
# close_encrypter ⇒ true
关闭加密器并清理自动加密资源。
876 877 878 879 880 |
# File 'lib/ Mongo/ 客户端.rb', 第 876 行 def close_encrypter @encrypter.关闭 if @encrypter true end |
#已关闭? ⇒布尔
856 857 858 |
# File 'lib/ Mongo/ 客户端.rb', 第 856 行 def 已关闭? !!@close end |
# cluster_options ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 |
# File 'lib/ Mongo/ 客户端.rb', 第 611 行 def # 当具有不同 CRUD_OPTIONS 的新客户端出现时,我们会股票集群 # 已请求;因此,集群不应获得任何这些 # 实例化时的选项 .拒绝 do |key, 值| CRUD_OPTIONS.包括?(key.to_sym) end.合并(merge)( # 但需要放回数据库进行身份验证... database: [:database], # 放入这些选项是为了兼容传统版本,但请注意 # 它们在客户端和集群上的值不必匹配 - # 应用程序应从客户端而不是集群读取这些值 max_read_retries: [:max_read_retries], read_retry_interval: [:read_retry_interval], ).点击 do || # 如果客户端已有集群,则将 srv_uri 转发到新集群 # 用于维护 SRV 监控的集群。 如果客户端是全新的, # 其构造函数手动设置 srv_uri。 if 集群 .update(srv_uri: 集群.[:srv_uri]) end end end |
# database_names (filter = {}, opts = {}) ⇒ Array<String>
获取所有数据库的名称。
932 933 934 |
# File 'lib/ Mongo/ 客户端.rb', 第 932 行 def database_names(筛选器 = {}, opts = {}) list_databases(筛选器, true, opts).收集{ |信息| 信息[' name '] } end |
#encrypted_fields_map ⇒哈希 | nil
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
如果在创建客户端时提供了加密字段映射哈希,则返回加密字段映射哈希。
1178 1179 1180 |
# File 'lib/ Mongo/ 客户端.rb', 第 1178 行 def encryption_fields_map @encrypted_fields_map ||= @options.获取(:auto_encryption_options, {})[:encrypted_fields_map] end |
# get_session (options = {}) ⇒会话| nil
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
如果可能,返回用于操作的会话。
如果设置了 :session 选项,则验证该会话并将其返回。 否则,如果部署支持会话,则创建一个新会话并将其返回。 创建新会话时,如果给出 :implicit 选项,则该会话将为隐式会话(生命周期由驱动程序管理),否则会话将为显式会话(生命周期由应用程序管理)。 如果部署不支持会话,则返回 nil。
1118 1119 1120 1121 1122 |
# File 'lib/ Mongo/ 客户端.rb', 第 1118 行 def get_session( = {}) get_session!() 救援 错误::SessionsNotSupported nil end |
#哈希⇒整数
获取客户端的哈希值。
207 208 209 |
# File 'lib/ Mongo/ 客户端.rb', 第 207 行 def 哈希 [集群, ].哈希 end |
#检查⇒ string
以string形式获取客户端检查结果。
674 675 676 |
# File 'lib/ Mongo/ 客户端.rb', 第 674 行 def 检查 " #<Mongo::Client:0 x #{ object_id} 集群= #{ 集群.summary} > " end |
# list_databases (filter = {}, name_only = false, opts = {}) ⇒ Array<Hash>
获取每个数据库的信息。
See https://mongodb.com/zh-cn/docs/manual/reference/command/listDatabases/
for more information and usage.
963 964 965 966 967 968 969 |
# File 'lib/ Mongo/ 客户端.rb', 第 963 行 def list_databases(筛选器 = {}, name_only = false, opts = {}) cmd = { listDatabases: 1 } cmd[:nameOnly] = !!name_only cmd[:filter] = 筛选器 除非 筛选器.空? cmd[:authorizedDatabases] = true if opts[:authorized_databases] 请使用(Database::ADMIN).database.read_command(cmd, opts).first[Database::数据库] end |
# list_mongo_databases (filter = {}, opts = {}) ⇒ Array< Mongo::Database >
返回 Mongo::Database 对象的列表。
986 987 988 989 990 |
# File 'lib/ Mongo/ 客户端.rb', 第 986 行 def list_mongo_databases(筛选器 = {}, opts = {}) database_names(筛选器, opts).收集 do |名称| Database.new(self, 名称, ) end end |
# max_read_retries ⇒整数
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
获取使用传统读取重试时客户端可以重试读取操作的最大次数。
642 643 644 |
# File 'lib/ Mongo/ 客户端.rb', 第 642 行 def max_read_retries [:max_read_retries] || 集群::MAX_READ_RETRIES end |
# max_write_retries ⇒整数
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
获取使用传统写入重试时客户端可以重试写入操作的最大次数。
662 663 664 |
# File 'lib/ Mongo/ 客户端.rb', 第 662 行 def max_write_retries [:max_write_retries] || 集群::MAX_WRITE_RETRIES end |
# read_concern ⇒哈希
获取此客户端的读关注(read concern)。
839 840 841 |
# File 'lib/ Mongo/ 客户端.rb', 第 839 行 def read_concern [:read_concern] end |
# read_preference ⇒ BSON::Document
从传递给客户端的选项中获取读取偏好(read preference)。
722 723 724 |
# File 'lib/ Mongo/ 客户端.rb', 第 722 行 def read_preference @read_preference ||= [:read] end |
# read_retry_interval ⇒浮点
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
获取使用传统读取重试时读取重试的时间间隔(以秒为单位)。
652 653 654 |
# File 'lib/ Mongo/ 客户端.rb', 第 652 行 def read_retry_interval [:read_retry_interval] || 集群::READ_RETRY_INTERVAL end |
# reconnect ⇒ true
重新连接客户端。
890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 |
# File 'lib/ Mongo/ 客户端.rb', 第 890 行 def 重新连接 地址 = 集群.地址.map(和:to_s) @connect_lock.同步 do do_close 救援 nil @cluster = 集群.new(地址, 监控, ) if @options[:auto_encryption_options] build_encrypter end @close = false end true end |
# server_selector ⇒ Mongo::ServerSelector
获取服务器选择器。 它要么使用客户端选项中定义的读取偏好,要么默认为主服务器选择器。
700 701 702 703 704 705 706 |
# File 'lib/ Mongo/ 客户端.rb', 第 700 行 def server_selector @server_selector ||= if read_preference ServerSelector.获取(read_preference) else ServerSelector.主节点 end end |
# start_session (options = {}) ⇒会话
会话不能同时被多个线程使用;会话对象不是线程安全的。
启动会话。
如果部署不支持会话,则引发 Mongo::Error::InvalidSession。 当驾驶员未连接到承载数据的服务器时(示例在故障转移期间),也可能会引发此异常。
1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 |
# File 'lib/ Mongo/ 客户端.rb', 第 1011 行 def start_session( = {}) 会话 = get_session!(.合并(merge)(隐式: false)) if block_given? 开始 产量 会话 确保 会话.end_session end else 会话 end end |
#摘要⇒ string
返回的摘要string的确切格式和布局不是驱动程序公共API的一部分,并且可能随时更改。
获取客户端状态摘要。
686 687 688 |
# File 'lib/ Mongo/ 客户端.rb', 第 686 行 def 总结 " #<Client cluster= #{ cluster .summary } } > " end |
#timeout_ms ⇒ Integer | nil
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回 timeout_ms 选项的值(如果设立)。
1184 1185 1186 |
# File 'lib/ Mongo/ 客户端.rb', 第 1184 行 def timeout_ms @options[:timeout_ms] end |
#timeout_sec ⇒ Float | nil
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回转换为秒的 timeout_ms 选项值。
1190 1191 1192 1193 1194 1195 1196 |
# File 'lib/ Mongo/ 客户端.rb', 第 1190 行 def timeout_sec if timeout_ms.nil? nil else timeout_ms / 1_000.0 end end |
#update_options(new_options) ⇒ Hash
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
从 new_options 更新此客户端的选项,从而验证所有选项。
新选项可以根据各种规则进行转换。 返回实际应用于客户端的选项的最终哈希值。
如果选项验证失败,此方法可能会发出警告或引发异常。 如果此方法引发异常,则应丢弃客户端(与构造函数引发异常的情况类似)。
789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 |
# File 'lib/ Mongo/ 客户端.rb', 第 789 行 def () = @options = self.class.( || {}) ().点击 do |opts| # 我们的选项已冻结 = @options.dup if [:write] && opts[:write_concern] .删除(:write) end if [:write_concern] && opts[:write] .删除(:write_concern) end .update(opts) @options = .冻结 = @options[:auto_encryption_options] != [:auto_encryption_options] # 如果有新的 auto_encryption_options,则创建新的加密器。 # 否则,允许新客户端与 # 原始客户端。 # # 如果 auto_encryption_options 为 nil,则将 @encrypter 设置为 nil,但不 # 关闭加密器,因为原始客户端可能仍在使用它。 if @options[:auto_encryption_options] && @connect_lock.同步 do build_encrypter end elsif @options[:auto_encryption_options].nil? @connect_lock.同步 do @encrypter = nil end end end end |
# use (name) ⇒ Mongo::Client
新客户端与原始客户端共享集群,因此也共享监控实例和监控事件订阅者。
创建一个新客户端,配置为使用具有提供名称的数据库,并使用此客户端中配置的其他选项。
741 742 743 |
# File 'lib/ Mongo/ 客户端.rb', 第 741 行 def 请使用(名称) 通过(database: 名称) end |
# watch (管道 = [], options = {}) ⇒ ChangeStream
变更流只允许“多数”读关注(read concern)。
出于支持可恢复性的目的,此辅助方法优于使用 $changeStream 阶段运行原始聚合。
从 MongoDB Server 3.6版本开始,聚合框架支持“$changeStream”管道阶段。 从版本4.0开始,此阶段允许用户请求为客户端集群中发生的所有更改发送通知。
1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 |
# File 'lib/ Mongo/ 客户端.rb', 第 1088 行 def 观看(管道 = [], = {}) return 请使用(Database::ADMIN).观看(管道, ) 除非 database.名称 == Database::ADMIN = .dup [:cursor_type] = :tailable_await if [:max_await_time_ms] mongo::Collection::查看::变更流.new( mongo::Collection::查看.new(self[" #{ Database :: COMMAND } .aggregate "], {}, ), 管道, mongo::Collection::查看::变更流::集群, ) end |
# with (new_options = nil) ⇒ Mongo::Client
根据给定的选项,返回的客户端可能与原始客户端共享集群,或者使用新集群创建。 如果创建了新集群,则新客户端上的监控事件订阅者将设置为默认事件订阅者集,并且原始客户端上的任何订阅者都不会被复制。
创建一个新客户端,并将传递的选项合并到该客户端的现有选项上。 对于在不改变原始客户端的情况下一次性更改特定选项非常有用。
763 764 765 766 767 768 769 770 771 772 773 |
# File 'lib/ Mongo/ 客户端.rb', 第 763 行 def 通过( = nil) 克隆.点击 do |客户端| opts = 客户端.( || 选项::已编辑.new) Database.创建(客户端) # 如果某些选项会影响集群,则不能使用该集群 # 已更改。 if (opts) 集群.创建(客户端, 监控: opts[:monitoring]) end end end |
# with_session (options = {}, &block) ⇒对象
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
如果可能,创建一个用于操作的会话,并将其生成提供的区块。
如果设置了 :session 选项,则验证该会话并使用它。 否则,如果部署支持会话,则创建并使用新会话。 创建新会话时,如果给出 :implicit 选项,则该会话将为隐式会话(生命周期由驱动程序管理),否则会话将为显式会话(生命周期由应用程序管理)。 如果部署不支持会话,则块的产出为 nil。
当区块完成时,如果会话已创建并且是隐式的,或者传入了隐式会话,则会话将结束,从而将其返回到可用会话池中。
1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 |
# File 'lib/ Mongo/ 客户端.rb', 第 1144 行 def with_session( = {}, 和块) # TODO:将其重新添加到 RUBY- 3174中。 #assert_not_close 会话 = get_session() 产量 会话 确保 if 会话 && 会话.隐式? 会话.end_session end end |
# write_concern ⇒ Mongo::WriteConcern
获取此客户端的写关注。 如果未提供选项,则使用默认的单服务器确认。
852 853 854 |
# File 'lib/ Mongo/ 客户端.rb', 第 852 行 def write_concern @write_concern ||= writeConcern.获取([:write_concern] || [:write]) end |