モジュール: Mongo::Collection::View::Readable
- 次のドキュメントに含まれます。
- Mongo::Collection::View
- 定義:
- lib/mongo/ コレクション/view/readable.rb
Overview
コレクション ビューの読み取り関連の動作を定義します。
インスタンス メソッドの概要を折りたたむ
-
#集計(パイプライン、オプション = {}) = 集計
コレクション ビューで集計を実行します。
-
# allow_disk_use = を表示
サーバーが検索操作を実行中に一時データをディスクに書き込むことを許可します。
-
# allow_Partial_results = を表示
一部のシャードがダウンした場合にクエリで部分的な結果を得ることができます。
-
#await_data = を表示
クエリのカーソルを開いたままデータを待つように指示します。
-
# batch_size (batch_size = nil) = 整数、ビュー
MongoDB からの結果の各バッチで返されたドキュメントの数。
-
#コメント(コメント=nil)=string, ビュー
クエリにコメントを関連付けます。
-
カウント(opts = {{}) = 整数
非推奨
非推奨。
代わりに、#count_documents または #estimated_document_count_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 (opts = {}) = 整数
コレクション内の一致するドキュメントの数を取得します。
-
# cursor_type (type =nil)=:tailable, ...
使用するカーソルの型。
-
distinct (field_name, opts = {{})= Array=========================================<Object>
特定のフィールドの個別の値のリストを取得します。
-
#estimate_document_count (ops = {}) = 整数
コレクション メタデータを使用して、コレクション内のドキュメント数の推定値を取得します。
-
#hint(hint = nil) ⇒ Hash, View
MongoDB がクエリに使用するように強制するインデックス。
-
#limit(limit = nil) ⇒ Integer, View
クエリから返されるDocsの最大数。
-
# map_reduce (map, reduce, options={{})= MapReduce
コレクション ビューで map-reduce 操作を実行します。
-
#max_await_time_ms (max = nil) = 整数、ビュー
カーソルに対する操作数を増やすための累積時間制限(ミリ秒単位)。
-
# max_scan (値 = nil) = 整数、ビュー
非推奨
非推奨。
MongoDB サーバー バージョン4.0以降、このオプションは非推奨です。
-
# max_time_ms (max = nil) = 整数、ビュー
カーソルに対する情報処理操作の累積時間制限(ミリ秒単位)。
-
# max_value (value = nil) = ハッシュ、ビュー
検索する最大値を設定します。
-
# min_value (value = nil) = ハッシュ、ビュー
検索する最小値を設定します。
-
#modifiers(doc = nil) ⇒ Hash, View
引数なしまたは nil 引数を指定して呼び出すと、 は現在のビューのレガシー(OP_QUERY)サーバー修飾子を返します。
-
#no_cursor_timeout ⇒ View
サーバーは通常、非アクティブな期間( 10分)の後にアイドル カーソルをタイムアウトして、過剰なメモリの使用を防ぎます。
- # parallel_scan (cursor_count、オプション = {}) = オブジェクト
-
#プロジェクション(ドキュメント = nil)= ハッシュ、ビュー
結果セット内の各ドキュメントに含める、または除外するフィールド。
-
#read (value = nil) = シンボル、ビュー
クエリに使用する 読み込み設定(read preference) 。
- #read_concern =オブジェクト private
- # read_preference =オブジェクト private
-
# return_key (値 = nil) = true, ...
インデックス付きフィールドのみを返すかどうかを設定します。
-
# show_disk_loc (値 = nil)=true, ... (#show_record_id)
各ドキュメントのディスク場所を表示するかどうかを設定します。
-
# skip (number = nil) = 整数、ビュー
結果を返す前にスキップするDocsの数。
-
#スナップショット(値 = nil) = オブジェクト
非推奨
非推奨。
MongoDB サーバー バージョン4.0以降、このオプションは非推奨です。
-
#sort (spec = nil) = ハッシュ、ビュー
結果セットがソートされるキーと方向のペア。
-
#timeout_ms(timeout_ms = nil) ⇒ Integer, View
操作ごとのタイムアウト(ミリ秒単位)。
インスタンス メソッドの詳細
#集計(パイプライン、オプション = {}) =集計
コレクション ビューで集計を実行します。
58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、58 行 デフォルト 集計(パイプライン, = {}) = @options.merge() ただし、 mongo. 集計 = 集計.新着情報(自己, パイプライン, ) # で、$merge と $out パイプライン ステージはドキュメントを # コレクションでは、実行時にキャッシュをクリアする必要があります。 # 1 つの名前空間ではなくキャッシュ全体をクリアするオプションは次のとおりです: $out ステージと $merge ステージは同じ名前空間に書き込む必要はありません 集計が実行される#。 クエリ キャッシュ.クリア 場合 集計.書込み (write)? 集計 end |
# allow_disk_use = を表示
サーバーが検索操作を実行中に一時データをディスクに書き込むことを許可します。
77 78 79 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、77 行 デフォルト allow_disk_use 構成する(:allow_disk_use, true) end |
# allow_Partial_results = を表示
一部のシャードがダウンした場合にクエリで部分的な結果を得ることができます。
89 90 91 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、89 行 デフォルト allow_ partial_results 構成する(:allow_ partial_results, true) end |
#await_data = を表示
クエリのカーソルを開いたままデータを待つように指示します。
101 102 103 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、101 行 デフォルト await_data 構成する(:await_data, true) end |
# batch_size (batch_size = nil) =整数、ビュー
1または負の数を指定することは、制限を設定することと同様です。
MongoDB からの結果の各バッチで返されたドキュメントの数。
118 119 120 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、118 行 デフォルト batch_size(batch_size = nil) 構成する(:batch_size, batch_size) end |
#コメント(コメント=nil)= string 、ビュー
profilingLevel を2に設定すると、クエリとともにコメントがプロファイル コレクションに記録されます。
クエリにコメントを関連付けます。
136 137 138 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、136 行 デフォルト comment(comment = nil) 構成する(:comment, comment) end |
カウント(opts = {{}) =整数
代わりに、#count_documents または #estimated_document_count_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コレクション内の一致するドキュメントの数を取得します。
172 173 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 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、172 行 デフォルト count(ops = {}) ops = @options.merge(ops) ただし、 mongo. cmd = { count: コレクション.name, query: フィルター } cmd[:skip] = ops[:skip] 場合 ops[:skip] cmd[:hint] = ops[:hint] 場合 ops[:hint] cmd[:limit] = ops[:limit] 場合 ops[:limit] 場合 read_concern cmd[:readConcern] = オプション::マッパー.transform_values_to_strings( read_concern ) end cmd[:maxTimeMS] = ops[:max_time_ms] 場合 ops[:max_time_ms] mongo::Lint.validate_userscore_read_preference(ops[:read]) read_pref = ops[:read] || read_preference セレクター = ServerSelector.得る(read_pref || server_selector) with_session(ops) 行う |セッション| context = 操作::Context.新着情報( クライアント: クライアント, セッション: セッション, operation_timeouts: operation_timeouts(ops) ) 操作 = 操作::数.新着情報( セレクター: cmd, db_name: database.name, 次のオプションがあります。 { limit: -1 }, read: read_pref, セッション: セッション, # 何らかの理由で照合は歴史的に として受け入れられました # string キー。 これは有効な使用として文書化されていないことに注意してください。 collation: ops[:collation] || ops[「照合」] || collation, comment: ops[:comment] ) 追跡.track_operation(操作, context) 行う read_with_retry(セッション, セレクター, context) 行う |サーバー| 操作.実行する( サーバー, context: context ) end.n.to_i end end end |
count_documents (opts = {}) =整数
コレクション内の一致するドキュメントの数を取得します。
242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、242 行 デフォルト count_documents(ops = {}) ops = @options.merge(ops) ただし、 mongo. パイプライン = [ { フィルターパイプラインパイプラインパイプライン_id照合照合照合パイプライン' $match ': フィルター } )パイプライン<< { ' $skip ': opts [:skip ] } が opts [:skip ]パイプラインの場合opts [:limit ]パイプライン{{ ' $group : { _id: 1, n: { ' $sum ': 1 opts = optsスライス( :hint,:max_time_ms,:read,:照合,:session,:comment,:timeout_ms ) ops [:照合 ] ||=照合 first = 集計(パイプライン、 opts )。最初に [ ' n ] がない限り、最初は 0 を返します。 to_i 終了 |
# cursor_type (type =nil)= :tailable 、...
使用するカーソルの型。 :tailable または :tailable_await になります。
665 666 667 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、665 行 デフォルト cursor_type(タイプ = nil) 構成する(: cursor_type, タイプ) end |
distinct (field_name, opts = {{})= Array =========================================<Object>
特定のフィールドの個別の値のリストを取得します。
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、344 行 デフォルト distinct(field_name, ops = {}) 発生 ArgumentError, '個別の操作のフィールド名は nil 以外である必要があります' 場合 field_name.nil? ops = @options.merge(ops) ただし、 mongo. cmd = { distinct コレクション.name, キー: field_name.to_s, query: フィルター, } cmd[:maxTimeMS] = ops[:max_time_ms] 場合 ops[:max_time_ms] 場合 read_concern cmd[:readConcern] = オプション::マッパー.transform_values_to_strings( read_concern ) end mongo::Lint.validate_userscore_read_preference(ops[:read]) read_pref = ops[:read] || read_preference セレクター = ServerSelector.得る(read_pref || server_selector) with_session(ops) 行う |セッション| context = 操作::Context.新着情報( クライアント: クライアント, セッション: セッション, operation_timeouts: operation_timeouts(ops) ) 操作 = 操作::distinct.新着情報( セレクター: cmd, db_name: database.name, 次のオプションがあります。 { limit: -1 }, read: read_pref, セッション: セッション, comment: ops[:comment], # 何らかの理由で照合は歴史的に として受け入れられました # string キー。 これは有効な使用として文書化されていないことに注意してください。 collation: ops[:collation] || ops[「照合」] || collation ) 追跡.track_operation(操作, context) 行う read_with_retry(セッション, セレクター, context) 行う |サーバー| 操作.実行する( サーバー, context: context ) end.最初に['values'] end end end |
#estimate_document_count (ops = {}) =整数
コレクション メタデータを使用して、コレクション内のドキュメント数の推定値を取得します。
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、278 行 デフォルト Estimated_document_count(ops = {}) ただし、 表示.フィルター.空の場合 発生 ArgumentError, フィルター を使用してクエリを実行すると、estimate_document_count を呼び出せません。 end %i[limit スキップ].各 行う |opt| 場合 .key?(opt) || ops.key?(opt) 発生 ArgumentError, 「 #{ opt } を使用してクエリを実行すると、estimate_document_count を呼び出せません 」 end end ops = @options.merge(ops) ただし、 mongo. mongo::Lint.validate_userscore_read_preference(ops[:read]) read_pref = ops[:read] || read_preference セレクター = ServerSelector.得る(read_pref || server_selector) with_session(ops) 行う |セッション| context = 操作::Context.新着情報( クライアント: クライアント, セッション: セッション, operation_timeouts: operation_timeouts(ops) ) cmd = { count: コレクション.name } cmd[:maxTimeMS] = ops[:max_time_ms] 場合 ops[:max_time_ms] cmd[:readConcern] = オプション::マッパー.transform_values_to_strings(read_concern) 場合 read_concern 操作 = 操作::数.新着情報( セレクター: cmd, db_name: database.name, read: read_pref, セッション: セッション, comment: ops[:comment] ) 追跡.track_operation(操作, context, op_name: 'estimatedDocumentCount') 行う read_with_retry(セッション, セレクター, context) 行う |サーバー| 結果 = 操作.実行する(サーバー, context: context) 結果.n.to_i end ヘルプ エラー::OperationFailure::ファミリー => e 発生 ただし、 e.コード == 26 # NamespaceNotFound # これは、集計パイプライン パスでのみ発生します #(サーバー4.9 +)。 以前のサーバーでは存在しない場合に対して0が返される必要があります。 # コレクション。 0 end end end |
#hint(hint = nil) ⇒ Hash, View
MongoDB がクエリに使用するように強制するインデックス。
398 399 400 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、398 行 デフォルト hint(hint = nil) 構成する(:hint, hint) end |
#limit(limit = nil) ⇒ Integer, View
クエリから返されるDocsの最大数。
412 413 414 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、412 行 デフォルト limit(limit = nil) 構成する(:limit, limit) end |
# map_reduce (map, reduce, options={{})= MapReduce
コレクション ビューで map-reduce 操作を実行します。
428 429 430 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、428 行 デフォルト map_reduce(map, reduce, = {}) mapReduce.新着情報(自己, map, reduce, @options.merge()) end |
#max_await_time_ms (max = nil) =整数、ビュー
カーソルに対する操作数を増やすための累積時間制限(ミリ秒単位)。
637 638 639 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、637 行 デフォルト max_await_time_ms(最大 = nil) 構成する(:max_await_time_ms, 最大) end |
# max_scan (値 = nil) =整数、ビュー
MongoDB サーバー バージョン4.0以降、このオプションは非推奨です。
スキャンするドキュメントの最大数を設定します。
445 446 447 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、445 行 デフォルト max_scan(価値 = nil) 構成する(:max_scan, 価値) end |
# max_time_ms (max = nil) =整数、ビュー
カーソルに対する情報処理操作の累積時間制限(ミリ秒単位)。
651 652 653 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、651 行 デフォルト max_time_ms(最大 = nil) 構成する(:max_time_ms, 最大) end |
# max_value (value = nil) =ハッシュ、ビュー
検索する最大値を設定します。
459 460 461 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、459 行 デフォルト max_value(価値 = nil) 構成する(:max_value, 価値) end |
# min_value (value = nil) =ハッシュ、ビュー
検索する最小値を設定します。
473 474 475 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、473 行 デフォルト min_value(価値 = nil) 構成する(:min_value, 価値) end |
#modifiers(doc = nil) ⇒ Hash, View
引数なしまたは nil 引数を指定して呼び出すと、 は現在のビューのレガシー(OP_QUERY)サーバー修飾子を返します。 ハッシュまたはサブクラスである必要がある nil 以外の引数で呼び出された場合、 は指定された修飾子を現在のビューにマージします。 入力ハッシュではstringキーとシンボルキーの両方が許可されます。
618 619 620 621 622 623 624 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、618 行 デフォルト modifiers(doc = nil) 場合 doc.nil? 操作::find::ビルダ::Modifiers.map_server_modifiers() else 新着情報(.merge(操作::find::ビルダ::Modifiers.(BSON::ドキュメント.新着情報(doc)))) end end |
#no_cursor_timeout ⇒ View
サーバーは通常、非アクティブな期間( 10分)の後にアイドル カーソルをタイムアウトして、過剰なメモリの使用を防ぎます。 それを防ぐには、このオプションを に設定します。
486 487 488 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、486 行 デフォルト no_cursor_timeout 構成する(:no_cursor_timeout, true) end |
# parallel_scan (cursor_count、オプション = {}) = オブジェクト
707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、707 行 デフォルト parallel_scan(cursor_count, = {}) セッション = 場合 [:session] # セッションは後で +options+ の 1 つによって上書きされます。 クライアント.get_session(@options) end サーバー = server_selector.[select_server](クラスター, nil, セッション) スペック = { coll_name: コレクション.name, db_name: database.name, cursor_count: cursor_count, read_concern: read_concern, セッション: セッション, }.update() セッション = スペック[:session] op = 操作::並列Scan.新着情報(スペック) # コンテキストオブジェクトは後続の で再利用されないことに注意してください。 #GetMore 操作。 context = 操作::Context.新着情報(クライアント: クライアント, セッション: セッション) 結果 = op.実行する(サーバー, context: context) 結果.cursor_ids.map 行う |cursor_id| スペック = { cursor_id: cursor_id, coll_name: コレクション.name, db_name: database.name, セッション: セッション, batch_size: batch_size, max_time_ms はここでは渡されていません。意図的に処理が行われていると仮定します。 } op = 操作::Get More.新着情報(スペック) context = 操作::Context.新着情報( クライアント: クライアント, セッション: セッション, connection_ global_id: 結果.connection_ global_id ) 結果 = 場合 サーバー.load_ balancer? カーソルが空のときに接続がチェックインされます。 接続 = サーバー.プール.checkpoint_out(context: context) op.execution_with_ connection(接続, context: context) else op.実行する(サーバー, context: context) end Cursor.新着情報(自己, 結果, サーバー, セッション: セッション) end end |
#プロジェクション(ドキュメント = nil)=ハッシュ、ビュー
0の値は、ドキュメントからフィールドを除外します。 1の値にはそれが含まれます。 値は、 _id 値を除き、すべて0またはすべての1である必要があります。 _id フィールドはデフォルトで含まれます。 明示的に除外する必要があります。
結果セット内の各ドキュメントに含める、または除外するフィールド。
504 505 506 507 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、504 行 デフォルト プロジェクション(ドキュメント = nil) validate_doc!(ドキュメント) 場合 ドキュメント 構成する(:プロジェクション, ドキュメント) end |
#read (value = nil) =シンボル、ビュー
クエリに が指定されていない場合は、コレクションの 読み込み設定(read preference)が使用されます。
クエリに使用する 読み込み設定(read preference) 。
520 521 522 523 524 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、520 行 デフォルト 読み取り(価値 = nil) return read_preference 場合 価値.nil? 構成する(:read, 価値) end |
#read_concern =オブジェクト
このメソッドは、プライベート API の一部です。 このメソッドは将来削除または変更される可能性があるため、可能な限り使用しないでください。
679 680 681 682 683 684 685 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、679 行 デフォルト read_concern 場合 [:session] & & [:session].in_transaction? [:session].送信(:txn_read_concern) || コレクション.クライアント.read_concern else コレクション.read_concern end end |
# read_preference =オブジェクト
このメソッドは、プライベート API の一部です。 このメソッドは将来削除または変更される可能性があるため、可能な限り使用しないでください。
688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、688 行 デフォルト read_preference @read_preference ||= begin # 操作の読み込み設定(read preference)は常に尊重され、次の要素が含まれます: 優先順位 。 トランザクション内では、次が必要になります。 # トランザクションの読み込み設定(read preference)とデフォルトのクライアントを無視する コレクションの読み込み設定 (read preference)。 トランザクションにない場合は、 クライアントにデフォルト設定されている読み込み設定 (read preference) を参照してください。 rp = 場合 [:read] [:read] elsif [:session] & & [:session].in_transaction? [:session].txn_read_preference || コレクション.クライアント.read_preference else コレクション.read_preference end Lint.validate_userscore_read_preference(rp) rp end end |
# return_key (値 = nil) = true , ...
インデックス付きフィールドのみを返すかどうかを設定します。
536 537 538 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、536 行 デフォルト return_key(価値 = nil) 構成する(:return_key, 価値) end |
# show_disk_loc (値 = nil) = true 、... とも呼ばれます: show_record_id
各ドキュメントのディスク場所を表示するかどうかを設定します。
551 552 553 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、551 行 デフォルト show_disk_loc(価値 = nil) 構成する(:show_disk_loc, 価値) end |
# skip (number = nil) =整数、ビュー
結果を返す前にスキップするDocsの数。
567 568 569 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、567 行 デフォルト スキップ(数値 = nil) 構成する(:skip, 数値) end |
#スナップショット(値 = nil) =オブジェクト
MongoDB サーバー バージョン4.0以降、このオプションは非推奨です。
true に設定されている場合、 はドキュメントを複数回返すことを防止します。
ビューの スナップショット 値を設定します。
585 586 587 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、585 行 デフォルト スナップショット(価値 = nil) 構成する(:snapshot, 価値) end |
#sort (spec = nil) =ハッシュ、ビュー
結果セットがソートされるキーと方向のペア。
600 601 602 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、600 行 デフォルト sort(スペック = nil) 構成する(:sort, スペック) end |
#timeout_ms(timeout_ms = nil) ⇒ Integer, View
操作ごとのタイムアウト(ミリ秒単位)。 正の整数である必要があります。
674 675 676 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、674 行 デフォルト timeout_ms(timeout_ms = nil) 構成する(:timeout_ms, timeout_ms) end |