类:Mongo::Collection
- 继承:
-
对象
- 对象
- Mongo::Collection
- 扩展方式:
- 可转发
- 包括:
- 助手、 QueryableEncryption 、 Retryable
- 定义于:
- lib/ Mongo/ 集合.rb 、
lib/
Mongo/
集合/view.rb、
lib/ Mongo/ 集合/helpers.rb、
lib/
Mongo/ 集合/view/iterable.rb、 lib/ Mongo/ 集合/view/可读。 rb, lib/ Mongo/ 集合/view/writable.rb, lib/
Mongo/ 集合/view/immutable.rb, lib/
Mongo/ 集合/view/map_reduce.rb,
lib/ Mongo/ 集合/view/ 聚合.rb, lib/
Mongo/ 集合/view/explainable.rb, lib/ Mongo/ 集合/view/change_stream.rb, lib/
Mongo/ 集合/queryable_encryption.rb, lib/ Mongo/ 集合/view/builder/map_reduce.rb, lib/
Mongo/ 集合/view/builder/ 聚合、lib/ Mongo/
集合/view/ 聚合/behavior.rb、lib/
Mongo/ 集合/view/change_stream/retryable.rb
Overview
表示数据库中的集合以及可直接应用于集合的操作。
在命名空间下定义
模块: 助手、 QueryableEncryption类:视图
常量摘要折叠
- CAPPED =
固定大小选项。
'固定大小'- NS =
ns字段常量。
'ns'- CHANGEABLE_OPTIONS =
可以通过 #with 方法在新的 Collection实例上更新的选项。
%i[读 read_concern 写 write_concern].冻结
- CREATE_COLLECTION_OPTIONS =
此常量是私有 API 的一部分。 应尽可能避免使用此常量,因为它将来可能会被删除或更改。
用于转换创建集合选项的选项映射。
{ time_series: :timeseries, expire_after: :expireAfterSeconds, clustered_index: :clusteredIndex, change_stream_pre_and_post_images: :changeStreamPreAndPostImages, encryption_fields: :encryptedFields, validator: :validator, view_on: :viewOn }
QueryableEncryption中包含的常量
QueryableEncryption::QE 2 _MIN_WIRE_VERSION
实例属性摘要折叠
-
#数据库⇒ Mongo::Database
只读
集合所在的数据库。
-
#名称⇒ string
只读
集合的名称。
-
# options ⇒ 哈希
只读
集合选项。
实例方法摘要折叠
-
# == (other) ⇒ true | false
检查集合是否等于另一个对象。
-
#aggregate (管道, options = {}) ⇒ View::Aggregation
对集合执行聚合。
-
# bulk_write (requests, options = {}) ⇒ BulkWrite::Result
执行批处理批量写入操作。
-
#固定大小? ⇒ true | false
集合是否有上限?
-
# count (filter = nil, options = {}) ⇒ Integer
已弃用
已弃用。
请改用#count_documents 或estimated_document_count。 但请注意,切换到 #count_documents 时需要替换以下操作符:
* $where should be replaced with $expr * $near should be replaced with $geoWithin with $center * $nearSphere should be replaced with $geoWithin with $centerSphere -
# count_documents (filter = {}, options = {}) ⇒ Integer
获取与查询匹配的文档数。
-
# create (opts = {}) ⇒ 结果
强制在数据库中创建集合。
-
# delete_many (过滤 = nil, options = {}) ⇒ 结果
从集合中删除文档。
-
# delete_one (过滤 = nil, options = {}) ⇒ 结果
从集合中删除文档。
-
# distinct (field_name, 过滤 = nil, options = {}) ⇒ Array<Object>
获取特定字段的非重复值列表。
-
# drop (opts = {}) ⇒ 结果
删除该集合。
-
#estimated_document_count (options = {}) ⇒ Integer
使用集合元数据获取集合中文档的估计数量。
-
# find (filter = nil, options = {}) ⇒ CollectionView
在集合中查找文档。
-
# find_one_and_delete (过滤, options = {}) =" BSON::Document ?
通过 findAndModify 在数据库中查找单个文档并将其删除,同时返回原始文档。
-
# find_one_and_replace (过滤, replacement, options = {}) ⇒ BSON::Document
查找并替换单个文档,并返回原始文档,除非另有说明。
-
#find_one_and_update(filter, update, options = {}) ⇒ BSON::Document
通过 findAndModify 查找单个文档并进行更新,除非另有指定,否则返回原始文档。
-
#indexes(options = {}) ⇒ Index::View
获取此集合的所有索引的视图。
-
#initialize (数据库, name, options = {}) ⇒ 集合
构造函数
实例化一个新集合。
-
# insert_many (documents, options = {}) ⇒ 结果
将提供的文档插入到集合中。
-
# insert_one (文档, opts = {}) ⇒ 结果
将单个文档插入到集合中。
-
#检查⇒ string
为集合进行美观打印的string检查。
-
#命名空间⇒ string
获取集合的完全限定命名空间。
-
# operation_timeups (opts = {}) ⇒ 哈希
private
在操作级别上设立的timeout_ms 值(如果有),和/或在集合/数据库/客户端级别上设立的timeout_ms(如果有)。
-
#parallel_scan (cursor_count, options = {}) ⇒ Array<Cursor>
对集合视图执行并行扫描。
-
# read_concern ⇒ 哈希
获取此集合实例的有效读关注。
-
# read_preference ⇒ 哈希
获取此集合的有效读取偏好(read preference)。
-
# replace_one (过滤, replacement, options = {}) ⇒ 结果
用新文档替换集合中的单个文档。
-
# search_indexes (options = {}) ⇒ SearchIndex::View
获取此集合的所有搜索索引的视图。
-
# server_selector ⇒ Mongo::ServerSelector
获取此集合的服务器选择器。
-
# system_collection? ⇒ 布尔
private
集合是否为系统集合。
-
#timeout_ms ⇒ Integer | nil
private
该数据库或相应客户端的操作超时。
-
#update_many(filter, update, options = {}) ⇒ Result
更新集合中的文档。
-
#update_one(filter, update, options = {}) ⇒ Result
更新集合中的单个文档。
-
# watch (pipeline = [], options = {}) ⇒ ChangeStream
允许用户请求就特定集合的所有更改发送通知。
-
# with (new_options) ⇒ Mongo::Collection
一个新的集合实例。
-
# write_concern ⇒ Mongo::WriteConcern
获取此集合的有效写关注。
-
# write_concern_with_session (session) ⇒ Mongo::WriteConcern
private
在给定会话的情况下,获取用于对此集合进行操作的写关注(write concern)。
助手中包含的方法
QueryableEncryption中包含的方法
#maybe_create_qe_collections , #maybe_drop_emm_collections
Retryable 中包含的方法
#read_worker、#select_server、#with_overload_retry、#write_worker
构造函数详情
#initialize (数据库, name, options = {}) ⇒集合
实例化一个新集合。
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/ Mongo/ 集合.rb', 第 163 行 def 初始化(database, 名称, = {}) 提高 错误::InvalidCollectionName.new 除非 名称 if [:write] && [:write_concern] && [:write] != [:write_concern] 提高 ArgumentError, " 如果同时给出了 :write 和 : write_concern ,则它们必须相同: #{ .inspect } " end @database = database @name = 名称.to_s.冻结 @options = .dup @timeout_ms = .删除(:timeout_ms) # WriteConcern对象支持 # if @options[:write_concern].is_a?(WriteConcern::Base) # # 缓存实例,以便我们不会不必要地重建它。 # @write_concern = @options[:write_concern] # @options[:write_concern] = @write_concern.options # end @options.冻结 end |
实例属性详细信息
#数据库⇒ Mongo::Database (readonly)
返回集合所在的数据库。
44 45 46 |
# File 'lib/ Mongo/ 集合.rb', 第 44 行 def database @database end |
# name ⇒ string (readonly)
返回集合的名称。
47 48 49 |
# File 'lib/ Mongo/ 集合.rb', 第 47 行 def 名称 @name end |
# options ⇒哈希(只读)
返回集合选项。
50 51 52 |
# File 'lib/ Mongo/ 集合.rb', 第 50 行 def @options end |
实例方法详细信息
# == (other) ⇒ true | false
检查集合是否等于另一个对象。 将检查名称和数据库是否相等。
89 90 91 92 93 |
# File 'lib/ Mongo/ 集合.rb', 第 89 行 def ==(其他) return false 除非 其他.is_a?(Collection) 名称 == 其他.名称 && database == 其他.database && == 其他. end |
#aggregate (管道, options = {}) ⇒ View::Aggregation
对集合执行聚合。
567 568 569 |
# File 'lib/ Mongo/ 集合.rb', 第 567 行 def 聚合(管道, = {}) 查看.new(self, {}, ).聚合(管道, ) end |
# bulk_write (requests, options = {}) ⇒ BulkWrite::Result
执行批处理批量写入操作。
939 940 941 |
# File 'lib/ Mongo/ 集合.rb', 第 939 行 def bulk_write(requests, = {}) 批量写入.new(self, requests, ).执行 end |
#固定大小? ⇒ true | false
集合是否有上限?
317 318 319 320 321 |
# File 'lib/ Mongo/ 集合.rb', 第 317 行 def 封顶? database.list_collections(过滤器: { 名称: 名称 }) .first &。dig('options', CAPPED) || false end |
# count (过滤 = nil, options = {}) ⇒ Integer
请改用#count_documents 或estimated_document_count。 但请注意,切换到 #count_documents 时需要替换以下操作符:
* $where should be replaced with $expr
* $near should be replaced with $geoWithin with $center
* $nearSphere should be replaced with $geoWithin with $centerSphere获取集合中匹配文档的估计数量。
681 682 683 |
# File 'lib/ Mongo/ 集合.rb', 第 681 行 def 数数(筛选器 = nil, = {}) 查看.new(self, 筛选器 || {}, ).数数() end |
# count_documents (过滤 = {}, options = {}) ⇒ Integer
获取与查询匹配的文档数。 与已弃用的 #count 方法不同,这将返回与过滤匹配的确切文档数(如果未提供过滤,则返回集合中文档的确切数),而不是估计值。
使用 #estimated_document_count 来检索使用集合元数据的集合中文档数量的估计值。
715 716 717 |
# File 'lib/ Mongo/ 集合.rb', 第 715 行 def count_documents(筛选器 = {}, = {}) 查看.new(self, 筛选器, ).count_documents() end |
# create (opts = {}) ⇒结果
强制在数据库中创建集合。
378 379 380 381 382 383 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 425 426 427 |
# File 'lib/ Mongo/ 集合.rb', 第 378 行 def 创建(opts = {}) # 将读取选项传递给 create 命令会导致其中断。 # 过滤掉读取选项。 此处也不包括会话,因为它获取 # 用于调用 with_session,并且不应该是 # 操作。 如果将其传递给操作,则BSON将失败 # 序列化。 # TODO 将读取选项列表放入类级常量中,当 # 我们找出它们的完整设立。 = 哈希[self..合并(merge)(opts).拒绝 do |key, _value| %w[读 read_preference read_concern 会话].包括?(key.to_s) end] # 将Ruby选项转换为服务器样式。 CREATE_COLLECTION_OPTIONS.每 do |ruby_key, server_key| [server_key] = .删除(ruby_key) if .键?(ruby_key) end 操作 = { 创建: 名称 }.合并(merge)() 操作.删除(:write) 操作.删除(:write_concern) 客户端.发送(:with_session, opts) do |会话| write_concern = if opts[:write_concern] writeConcern.获取(opts[:write_concern]) else self.write_concern end 上下文 = 操作::上下文.new( 客户端: 客户端, 会话: 会话 ) 操作 = 操作::创建.new( 选择器: 操作, db_name: database.名称, write_concern: write_concern, 会话: 会话, # 请注意,这些是集合选项,排序规则不是 # 取自传递给 create 方法的选项。 排序规则: [:collation] || [' collation '], validator: [:validator] ) 追踪器.trace_operation(操作, 上下文, op_name: 'createCollection') do 也许_create_qe_collections(opts[:encrypted_fields], 客户端, 会话) do |encryption_fields| 操作.encryption_fields = encryption_fields 操作.执行( next_primary(nil, 会话), 上下文: 上下文 ) end end end end |
# delete_many (filter = nil, options = {}) ⇒结果
从集合中删除文档。
991 992 993 |
# File 'lib/ Mongo/ 集合.rb', 第 991 行 def delete_many(筛选器 = nil, = {}) find(筛选器, ).delete_many() end |
# delete_one (过滤 = nil, options = {}) ⇒结果
从集合中删除文档。
965 966 967 |
# File 'lib/ Mongo/ 集合.rb', 第 965 行 def delete_one(筛选器 = nil, = {}) find(筛选器, ).delete_one() end |
# distinct (field_name, 过滤 = nil, options = {}) ⇒ Array<Object>
获取特定字段的非重复值列表。
767 768 769 |
# File 'lib/ Mongo/ 集合.rb', 第 767 行 def distinct(field_name, 筛选器 = nil, = {}) 查看.new(self, 筛选器 || {}, ).distinct(field_name, ) end |
# drop (opts = {}) ⇒结果
如果集合不存在,则会抑制返回的错误。
删除集合。 还会删除与集合关联的所有索引,以及关联的Queryable Encryption集合。
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 |
# File 'lib/ Mongo/ 集合.rb', 第 451 行 def 删除(opts = {}) 客户端.with_session(opts) do |会话| 上下文 = 操作::上下文.new( 客户端: 客户端, 会话: 会话, operation_timeups: operation_timeups(opts) ) temp_write_concern = write_concern write_concern = if opts[:write_concern] writeConcern.获取(opts[:write_concern]) else temp_write_concern end 操作 = 操作::删除.new({ 选择器: { drop: 名称 }, db_name: database.名称, write_concern: write_concern, 会话: 会话, }) 追踪器.trace_operation(操作, 上下文, op_name: 'dropCollection') do 也许_drop_emm_collections(opts[:encrypted_fields], 客户端, 会话) do do_drop(操作, 会话, 上下文) end end end end |
#estimated_document_count (options = {}) ⇒ Integer
使用集合元数据获取集合中文档的估计数量。
使用 #count_documents 检索集合中文档的确切数量,或对与筛选器匹配的文档进行计数。
740 741 742 |
# File 'lib/ Mongo/ 集合.rb', 第 740 行 def estimated_document_count( = {}) 查看.new(self, {}, ).estimated_document_count() end |
# find (过滤 = nil, options = {}) ⇒ CollectionView
在集合中查找文档。
531 532 533 |
# File 'lib/ Mongo/ 集合.rb', 第 531 行 def find(筛选器 = nil, = {}) 查看.new(self, 筛选器 || {}, ) end |
# find_one_and_delete (过滤, options = {}) = " BSON::Document ?
通过 findAndModify 在数据库中查找单个文档并将其删除,同时返回原始文档。
1164 1165 1166 |
# File 'lib/ Mongo/ 集合.rb', 第 1164 行 def find_one_and_delete(筛选器, = {}) find(筛选器, ).find_one_and_delete() end |
# find_one_and_replace (过滤, replacement, options = {}) ⇒ BSON::Document
查找并替换单个文档,并返回原始文档,除非另有说明。
1250 1251 1252 |
# File 'lib/ Mongo/ 集合.rb', 第 1250 行 def find_one_and_replace(筛选器, 替换, = {}) find(筛选器, ).find_one_and_update(替换, ) end |
# find_one_and_update (filter, update, options = {}) ⇒ BSON::Document
通过 findAndModify 查找单个文档并进行更新,除非另有指定,否则返回原始文档。
1208 1209 1210 |
# File 'lib/ Mongo/ 集合.rb', 第 1208 行 def find_one_and_update(筛选器, update, = {}) find(筛选器, ).find_one_and_update(update, ) end |
#indexes(options = {}) ⇒ Index::View
获取此集合的所有索引的视图。 可以迭代或具有更多操作。
784 785 786 |
# File 'lib/ Mongo/ 集合.rb', 第 784 行 def 索引( = {}) Index::查看.new(self, ) end |
# insert_many (documents, options = {}) ⇒结果
将提供的文档插入到集合中。
907 908 909 910 911 912 |
# File 'lib/ Mongo/ 集合.rb', 第 907 行 def insert_many(文档, = {}) 查询缓存.clear_namespace(namespace) inserts = 文档.map { |doc| { insert_one: doc } } bulk_write(inserts, ) end |
# insert_one (文档, opts = {}) ⇒结果
将单个文档插入到集合中。
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 |
# File 'lib/ Mongo/ 集合.rb', 第 845 行 def insert_one(文档, opts = {}) 查询缓存.clear_namespace(namespace) 客户端.with_session(opts) do |会话| write_concern = if opts[:write_concern] writeConcern.获取(opts[:write_concern]) else write_concern_with_session(会话) end 提高 ArgumentError, ' 要插入的文档不能为 nil ' if 文档.nil? 上下文 = 操作::上下文.new( 客户端: 客户端, 会话: 会话, operation_timeups: operation_timeups(opts) ) 操作 = 操作::Insert.new( 文档: [ 文档 ], db_name: database.名称, coll_name: 名称, write_concern: write_concern, bypass_document_validation: !!opts[:bypass_document_validation], 选项: opts, id_generator: 客户端.[:id_generator], 会话: 会话, comment: opts[:comment] ) 追踪器.trace_operation(操作, 上下文) do write_with_retry(write_concern, 上下文: 上下文) do |连接, txn_num, 上下文| 操作.txn_num = txn_num 操作.execute_with_connection(连接, 上下文: 上下文) end end end end |
#检查⇒ string
为集合进行美观打印的string检查。
818 819 820 |
# File 'lib/ Mongo/ 集合.rb', 第 818 行 def 检查 " #<Mongo::Collection: 0 x #{ object_id } 命名空间= #{ 命名空间 } > " end |
#命名空间⇒ string
获取集合的完全限定命名空间。
1262 1263 1264 |
# File 'lib/ Mongo/ 集合.rb', 第 1262 行 def namespace " #{ 数据库 . name } . #{ name } " end |
# operation_timeups (opts = {}) ⇒ 哈希
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回在操作级别(如果有)上设立的timeout_ms 值,和/或在集合/数据库/客户端级别上设立的timeout_ms(如果有)。
1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 |
# File 'lib/ Mongo/ 集合.rb', 第 1287 行 def operation_timeups(opts = {}) # TODO: 我们应该重新评估是否需要分别设置两次超时。 {}.点击 do |结果| if opts[:timeout_ms].nil? 结果[:inherited_timeout_ms] = timeout_ms else 结果[:operation_timeout_ms] = opts.删除(:timeout_ms) end end end |
# parallel_scan (cursor_count, options = {}) ⇒ Array< Cursor >
对集合视图执行并行扫描。
返回最多包含 cursor_count 个可并发迭代的游标的列表。只要在扫描期间未修改集合,每个文档就会在游标的一个结果集中出现一次。
1022 1023 1024 |
# File 'lib/ Mongo/ 集合.rb', 第 1022 行 def parallel_scan(cursor_count, = {}) find({}, ).parallel_scan(cursor_count, ) end |
# read_concern ⇒哈希
获取此集合实例的有效读关注。
如果集合选项中提供了读关注(read concern),则返回该读关注(read concern),否则将返回数据库的有效读关注(read concern)。
194 195 196 |
# File 'lib/ Mongo/ 集合.rb', 第 194 行 def read_concern [:read_concern] || database.read_concern end |
# read_preference ⇒哈希
获取此集合的有效读取偏好(read preference)。
如果集合选项中提供了读取偏好(read preference),则返回该读取偏好(read preference),否则将返回数据库的有效读取偏好(read preference)。
222 223 224 |
# File 'lib/ Mongo/ 集合.rb', 第 222 行 def read_preference @read_preference ||= [:read] || database.read_preference end |
# replace_one (过滤, replacement, options = {}) ⇒结果
用新文档替换集合中的单个文档。
1058 1059 1060 |
# File 'lib/ Mongo/ 集合.rb', 第 1058 行 def replace_one(筛选器, 替换, = {}) find(筛选器, ).replace_one(替换, ) end |
# search_indexes (options = {}) ⇒ SearchIndex::View
只能提供 ID 或名称之一;指定两者是错误的,尽管可以安全地省略两者。
获取此集合的所有搜索索引的视图。 可以迭代或直接操作。 如果给出了ID或名称,则迭代器将仅返回指示的索引。 对于所有其他操作,将忽略 ID 和名称。
806 807 808 |
# File 'lib/ Mongo/ 集合.rb', 第 806 行 def search_indexes( = {}) SearchIndex::查看.new(self, ) end |
# server_selector ⇒ Mongo::ServerSelector
获取此集合的服务器选择器。
206 207 208 |
# File 'lib/ Mongo/ 集合.rb', 第 206 行 def server_selector @server_selector ||= ServerSelector.获取(read_preference || database.server_selector) end |
# system_collection? ⇒布尔
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
集合是否为系统集合。
1271 1272 1273 |
# File 'lib/ Mongo/ 集合.rb', 第 1271 行 def system_collection? 名称.start_with?('系统。 ') end |
#timeout_ms ⇒ Integer | nil
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回此数据库或相应客户端的操作超时时间。
1279 1280 1281 |
# File 'lib/ Mongo/ 集合.rb', 第 1279 行 def timeout_ms @timeout_ms || database.timeout_ms end |
#update_many(filter, update, options = {}) ⇒ Result
更新集合中的文档。
1091 1092 1093 |
# File 'lib/ Mongo/ 集合.rb', 第 1091 行 def update_many(筛选器, update, = {}) find(筛选器, ).update_many(update, ) end |
#update_one(filter, update, options = {}) ⇒ Result
更新集合中的单个文档。
1129 1130 1131 |
# File 'lib/ Mongo/ 集合.rb', 第 1129 行 def update_one(筛选器, update, = {}) find(筛选器, ).update_one(update, ) end |
# watch (管道 = [], options = {}) ⇒ ChangeStream
变更流只允许“大多数”读关注(read concern)。
出于支持可恢复性的目的,此辅助方法优于使用 $changeStream 阶段运行原始聚合。
允许用户请求就特定集合的所有更改发送通知。
642 643 644 645 646 |
# File 'lib/ Mongo/ 集合.rb', 第 642 行 def 观看(管道 = [], = {}) = .dup [:cursor_type] = :tailable_await if [:max_await_time_ms] 查看::变更流.new(查看.new(self, {}, ), 管道, nil, ) end |
# with (new_options) ⇒ Mongo::Collection
返回 一个新的集合实例。
299 300 301 302 303 304 305 306 307 |
# File 'lib/ Mongo/ 集合.rb', 第 299 行 def 通过() .密钥.每 do |k| 提高 错误::UnchangeableCollectionOption.new(k) 除非 CHANGEABLE_OPTIONS.包括?(k) end = @options.dup .删除(:write) if [:write] && [:write_concern] .删除(:write_concern) if [:write_concern] && [:write] Collection.new(database, 名称, .update()) end |
# write_concern ⇒ Mongo::WriteConcern
获取此集合的有效写关注。
如果集合选项中提供了写关注(write concern),则返回该写关注(write concern),否则将返回数据库的有效写关注(write concern)。
238 239 240 241 242 |
# File 'lib/ Mongo/ 集合.rb', 第 238 行 def write_concern @write_concern ||= writeConcern.获取( [:write_concern] || [:write] || database.write_concern ) end |
# write_concern_with_session (session) ⇒ Mongo::WriteConcern
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
在给定会话的情况下,获取用于对此集合进行操作的写关注(write concern)。
如果会话位于ACID 事务中并且集合具有未确认的写关注(write concern),删除写入关注的 :w 选项。否则,返回未修改的写关注(write concern)。
255 256 257 258 259 260 261 262 263 |
# File 'lib/ Mongo/ 集合.rb', 第 255 行 def write_concern_with_session(会话) wc = write_concern if 会话 && 会话.in_transaction? && wc && !wc.已确认? opts = wc..dup opts.删除(:w) return writeConcern.获取(opts) end wc end |