モジュール: 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 (only works on 3.6+) * $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
操作ごとのタイムアウト(ミリ秒単位)。
インスタンス メソッドの詳細
#集計(パイプライン、オプション = {}) =集計
コレクション ビューで集計を実行します。
61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、61 行 デフォルト 集計(パイプライン, = {}) = @options.merge() ただし、 mongo. 集計 = 集計.新着情報(自己, パイプライン, ) # で、$merge と $out パイプライン ステージはドキュメントを # コレクションでは、実行時にキャッシュをクリアする必要があります。 # 1 つの名前空間ではなくキャッシュ全体をクリアするオプションは次のとおりです: $out ステージと $merge ステージは同じ名前空間に書き込む必要はありません 集計が実行される#。 クエリ キャッシュ.クリア 場合 集計.書込み (write)? 集計 end |
# allow_disk_use = を表示
サーバーが検索操作を実行中に一時データをディスクに書き込むことを許可します。
80 81 82 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、80 行 デフォルト allow_disk_use 構成する(:allow_disk_use, true) end |
# allow_Partial_results = を表示
一部のシャードがダウンした場合にクエリで部分的な結果を得ることができます。
92 93 94 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、92 行 デフォルト allow_ partial_results 構成する(:allow_ partial_results, true) end |
#await_data = を表示
クエリのカーソルを開いたままデータを待つように指示します。
104 105 106 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、104 行 デフォルト await_data 構成する(:await_data, true) end |
# batch_size (batch_size = nil) =整数、ビュー
1または負の数を指定することは、制限を設定することと同様です。
MongoDB からの結果の各バッチで返されたドキュメントの数。
121 122 123 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、121 行 デフォルト batch_size(batch_size = nil) 構成する(:batch_size, batch_size) end |
#コメント(コメント=nil)= string 、ビュー
profilingLevel を2に設定すると、クエリとともにコメントがプロファイル コレクションに記録されます。
クエリにコメントを関連付けます。
139 140 141 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、139 行 デフォルト comment(comment = nil) 構成する(:comment, comment) end |
カウント(opts = {{}) =整数
代わりに、#count_documents または #estimated_document_count_count を使用してください。 ただし、#count_documents に切り替えるときに次の演算子を置き換える必要があることに注意してください。
* $where should be replaced with $expr (only works on 3.6+)
* $near should be replaced with $geoWithin with $center
* $nearSphere should be replaced with $geoWithin with $centerSphere
コレクション内の一致するドキュメントの数を取得します。
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 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、175 行 デフォルト count(ops = {}) ops = @options.merge(ops) ただし、 mongo. cmd = { :count => コレクション.name, : クエリ => フィルター } 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) ) read_with_retry(セッション, セレクター, context) 行う |サーバー| 操作::数.新着情報( セレクター: cmd, db_name: database.name, 次のオプションがあります。 {:limit => -1}, read: read_pref, セッション: セッション, # 何らかの理由で照合は歴史的に として受け入れられました # string キー。 これは有効な使用として文書化されていないことに注意してください。 collation: ops[:collation] || ops[「照合」] || collation, comment: ops[:comment], ).実行する( サーバー, context: context ) end.n.to_i end end |
count_documents (opts = {}) =整数
コレクション内の一致するドキュメントの数を取得します。
241 242 243 244 245 246 247 248 249 250 251 252 253 254 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、241 行 デフォルト count_documents(ops = {}) ops = @options.merge(ops) ただし、 mongo. パイプライン = [:'$match' => フィルター] パイプライン < { :'$skip' => ops[:skip] } 場合 ops[:skip] パイプライン < { :'$limit' => ops[:limit] } 場合 ops[:limit] パイプライン < { :'$group' => { _id: 1, n: { :'$sum' => 1 } } } ops = ops.スライス(:hint, :max_time_ms, :read, :collation, :session, :comment, :timeout_ms) ops[:collation] ||= collation 最初に = 集計(パイプライン, ops).最初に return 0 ただし、 最初に 最初に['n'].to_i end |
# cursor_type (type =nil)= :tailable 、...
使用するカーソルの型。 :tailable または :tailable_await になります。
660 661 662 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、660 行 デフォルト cursor_type(タイプ = nil) 構成する(: cursor_type, タイプ) end |
distinct (field_name, opts = {{})= Array =========================================<Object>
特定のフィールドの個別の値のリストを取得します。
343 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 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、343 行 デフォルト distinct(field_name, ops = {}) 場合 field_name.nil? 発生 ArgumentError, '個別の操作のフィールド名は nil 以外である必要があります' end ops = @options.merge(ops) ただし、 mongo. cmd = { : distinct => コレクション.name, :key => field_name.to_s, : クエリ => フィルター, } 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) ) read_with_retry(セッション, セレクター, context) 行う |サーバー| 操作::distinct.新着情報( セレクター: cmd, db_name: database.name, 次のオプションがあります。 {:limit => -1}, read: read_pref, セッション: セッション, comment: ops[:comment], # 何らかの理由で照合は歴史的に として受け入れられました # string キー。 これは有効な使用として文書化されていないことに注意してください。 collation: ops[:collation] || ops[「照合」] || collation, ).実行する( サーバー, context: context ) end.最初に['values'] end end |
#estimate_document_count (ops = {}) =整数
コレクション メタデータを使用して、コレクション内のドキュメント数の推定値を取得します。
276 277 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 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、276 行 デフォルト 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) ) read_with_retry(セッション, セレクター, context) 行う |サーバー| cmd = { count: コレクション.name } cmd[:maxTimeMS] = ops[:max_time_ms] 場合 ops[:max_time_ms] 場合 read_concern cmd[:readConcern] = オプション::マッパー.transform_values_to_strings(read_concern) end 結果 = 操作::数.新着情報( セレクター: cmd, db_name: database.name, read: read_pref, セッション: セッション, comment: ops[:comment], ).実行する(サーバー, context: context) 結果.n.to_i end end ヘルプ エラー::OperationFailure::ファミリー => 除外 場合 除外.コード == 26 # NamespaceNotFound # これは、集計パイプライン パスでのみ発生します #(サーバー4.9 +)。 以前のサーバーでは存在しない場合に対して0が返される必要があります。 # コレクション。 0 else 発生 end end |
#hint(hint = nil) ⇒ Hash, View
MongoDB がクエリに使用するように強制するインデックス。
394 395 396 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、394 行 デフォルト hint(hint = nil) 構成する(:hint, hint) end |
#limit(limit = nil) ⇒ Integer, View
クエリから返されるDocsの最大数。
408 409 410 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、408 行 デフォルト limit(limit = nil) 構成する(:limit, limit) end |
# map_reduce (map, reduce, options={{})= MapReduce
コレクション ビューで map-reduce 操作を実行します。
424 425 426 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、424 行 デフォルト map_reduce(map, reduce, = {}) mapReduce.新着情報(自己, map, reduce, @options.merge()) end |
#max_await_time_ms (max = nil) =整数、ビュー
カーソルに対する操作数を増やすための累積時間制限(ミリ秒単位)。
632 633 634 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、632 行 デフォルト max_await_time_ms(最大 = nil) 構成する(:max_await_time_ms, 最大) end |
# max_scan (値 = nil) =整数、ビュー
MongoDB サーバー バージョン4.0以降、このオプションは非推奨です。
スキャンするドキュメントの最大数を設定します。
441 442 443 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、441 行 デフォルト max_scan(価値 = nil) 構成する(:max_scan, 価値) end |
# max_time_ms (max = nil) =整数、ビュー
カーソルに対する情報処理操作の累積時間制限(ミリ秒単位)。
646 647 648 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、646 行 デフォルト max_time_ms(最大 = nil) 構成する(:max_time_ms, 最大) end |
# max_value (value = nil) =ハッシュ、ビュー
検索する最大値を設定します。
455 456 457 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、455 行 デフォルト max_value(価値 = nil) 構成する(:max_value, 価値) end |
# min_value (value = nil) =ハッシュ、ビュー
検索する最小値を設定します。
469 470 471 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、469 行 デフォルト min_value(価値 = nil) 構成する(:min_value, 価値) end |
#modifiers(doc = nil) ⇒ Hash, View
引数なしまたは nil 引数を指定して呼び出すと、 は現在のビューのレガシー(OP_QUERY)サーバー修飾子を返します。 ハッシュまたはサブクラスである必要がある nil 以外の引数で呼び出された場合、 は指定された修飾子を現在のビューにマージします。 入力ハッシュではstringキーとシンボルキーの両方が許可されます。
613 614 615 616 617 618 619 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、613 行 デフォルト modifiers(doc = nil) 場合 doc.nil? 操作::find::ビルダ::Modifiers.map_server_modifiers() else 新着情報(.merge(操作::find::ビルダ::Modifiers.(BSON::ドキュメント.新着情報(doc)))) end end |
#no_cursor_timeout ⇒ View
サーバーは通常、非アクティブな期間( 10分)の後にアイドル カーソルをタイムアウトして、過剰なメモリの使用を防ぎます。 それを防ぐには、このオプションを に設定します。
482 483 484 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、482 行 デフォルト no_cursor_timeout 構成する(:no_cursor_timeout, true) end |
# parallel_scan (cursor_count、オプション = {}) = オブジェクト
702 703 704 705 706 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 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、702 行 デフォルト parallel_scan(cursor_count, = {}) 場合 [:session] # セッションは後で +options+ の 1 つによって上書きされます。 セッション = クライアント.get_session(@options) else セッション = nil 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, to_return: 0, 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 フィールドはデフォルトで含まれます。 明示的に除外する必要があります。
結果セット内の各ドキュメントに含める、または除外するフィールド。
500 501 502 503 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、500 行 デフォルト プロジェクション(ドキュメント = nil) validate_doc!(ドキュメント) 場合 ドキュメント 構成する(:プロジェクション, ドキュメント) end |
#read (value = nil) =シンボル、ビュー
クエリに が指定されていない場合は、コレクションの 読み込み設定(read preference)が使用されます。
クエリに使用する 読み込み設定(read preference) 。
516 517 518 519 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、516 行 デフォルト 読み取り(価値 = nil) return read_preference 場合 価値.nil? 構成する(:read, 価値) end |
#read_concern =オブジェクト
このメソッドは、プライベート API の一部です。 このメソッドは将来削除または変更される可能性があるため、可能な限り使用しないでください。
674 675 676 677 678 679 680 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、674 行 デフォルト read_concern 場合 [:session] & & [:session].in_transaction? [:session].送信(:txn_read_concern) || コレクション.クライアント.read_concern else コレクション.read_concern end end |
# read_preference =オブジェクト
このメソッドは、プライベート API の一部です。 このメソッドは将来削除または変更される可能性があるため、可能な限り使用しないでください。
683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、683 行 デフォルト 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 , ...
インデックス付きフィールドのみを返すかどうかを設定します。
531 532 533 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、531 行 デフォルト return_key(価値 = nil) 構成する(:return_key, 価値) end |
# show_disk_loc (値 = nil) = true 、... とも呼ばれます: show_record_id
各ドキュメントのディスク場所を表示するかどうかを設定します。
546 547 548 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、546 行 デフォルト show_disk_loc(価値 = nil) 構成する(:show_disk_loc, 価値) end |
# skip (number = nil) =整数、ビュー
結果を返す前にスキップするDocsの数。
562 563 564 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、562 行 デフォルト スキップ(数値 = nil) 構成する(:skip, 数値) end |
#スナップショット(値 = nil) =オブジェクト
MongoDB サーバー バージョン4.0以降、このオプションは非推奨です。
true に設定されている場合、 はドキュメントを複数回返すことを防止します。
ビューの スナップショット 値を設定します。
580 581 582 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、580 行 デフォルト スナップショット(価値 = nil) 構成する(:snapshot, 価値) end |
#sort (spec = nil) =ハッシュ、ビュー
結果セットがソートされるキーと方向のペア。
595 596 597 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、595 行 デフォルト sort(スペック = nil) 構成する(:sort, スペック) end |
#timeout_ms(timeout_ms = nil) ⇒ Integer, View
操作ごとのタイムアウト(ミリ秒単位)。 正の整数である必要があります。
669 670 671 |
# ファイル 'lib/mongo/ コレクション/view/readable.rb' は、669 行 デフォルト timeout_ms(timeout_ms = nil) 構成する(:timeout_ms, timeout_ms) end |