クラス: Mongo::Grid::FSbucket
- 継承:
-
オブジェクト
- オブジェクト
- Mongo::Grid::FSbucket
- 次による拡張機能。
- 転送可能
- 定義:
- lib/mongo/ Grid/fs_bucket.rb
、lib/mongo/ Grid/stream.rb、lib/mongo/
Grid/stream/read.rb、lib/mongo/
Grid/stream/write.rb
Overview
データベース内の GridFS のビューを表します。
名前空間で定義済み
Modules: ストリーム
定数の概要の削減
- DEFAULT_ROOT =
デフォルトのルートプレフィックス。
'fs'.freeze
- チャンク_INDEX =
チャンク コレクション インデックスの仕様。
{ :files_id => 1, :n => 1 }.freeze
- FILES_INDEX =
ファイル コレクション インデックスの仕様。
{ ファイル名: 1, アップロードDate: 1 }.freeze
インスタンス属性の概要を折りたたむ
-
#chunks_collection ⇒ Collection
readOnly
Chunks_collection チャンクのコレクション。
-
#database ⇒ Database
readOnly
Database The database.
-
#files_collection ⇒ Collection
readOnly
ファイル_コレクション ファイルのコレクション。
-
#options ⇒ Hash
readOnly
オプション FSbucket オプション。
インスタンス メソッドの概要を折りたたむ
-
delete (ID, opts = {}) = 結果 = 結果
ID で識別される単一のファイルを GridFS から削除します。
-
# delete_one (ファイル, opts = {}) = 結果 = 結果
GridFS から単一ファイルを削除します。
-
ダウンロード_to_stream ( ID , io) = オブジェクト
ID で指定されたファイルの内容をダウンロードし、宛先 io オブジェクトに書込みます。
-
ダウンロード_to_stream_by_name(ファイル名, io, opts = {}) = オブジェクト
ファイル名とオプションの 変更によって指定された保存済みファイルの内容をダウンロードし、その内容を宛先 io オブジェクトに書込みます。
-
#drop(ops = {}) = オブジェクト
このバケット を実装するコレクションを削除します。
-
# find (Selector = nil、Options = {}) = CollectionView
指定されたセレクターに一致するファイル コレクション ドキュメントを検索します。
-
# find_one (Selector = nil) = Grid::File
非推奨
非推奨。
代わりに - 1の制限で #find を使用してください。 バージョン3.0で削除されます。
-
#initialize(database, options = {}) ⇒ FSBucket
コンストラクター
GridFS を作成します。
-
#insert_one(file) ⇒ BSON::ObjectId
非推奨
非推奨。
代わりに、#upload_from_stream または #open_upload_stream を使用してください。 バージョン3.0で削除されます。
-
#open_Download_stream ( ID 、オプション = nil){{|The| ... } = Stream::Read
ID で指定されたファイルをダウンロードできるストリームを開きます。
-
#open_Download_stream_by_name (ファイル名、opts = {}){{|The| ... } = Stream::Read
アプリケーションがファイル名で指定された保存済みファイルの内容と オプションのリダイレクトを読み取ることができるストリームを開きます。
-
#open_upload_stream (ファイル名、opts ={{}){{|The| ... } = Stream::Write
ファイルまたは long の内容を書き込むことができる GridFS へのアップロードストリームを開きます。
-
# prefix = string
GridFS のプレフィックスを取得します。
-
#read_preference = BSON::Document
読み込み設定 (read preference) を取得します。
-
#upload_from_stream(filename, io, opts = {}) ⇒ BSON::ObjectId
ユーザー ファイルを GridFS バケットにアップロードします。
-
#write_concern = Mongo::WriteConcern
書込み保証 (write concern) を取得します。
コンストラクターの詳細
#initialize(database, options = {}) ⇒ FSBucket
GridFS を作成します。
70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
ファイル 'lib/mongo/ Grid/fs_bucket.rb '、行 70 デフォルト 初期化(database, = {}) @database = database @options = .dup =開始 WriteConcern オブジェクト サポート の場合 @options[:write_concern].is_a?(WriteConcern::Base) # インスタンスをキャッシュして、不必要に再構築されないようにします。 @write_concern = @options[:write_concern] @options[:write_concern] = @write_concern.options end =end @options.freeze @chunks_collection = database[chunks_name] @files_collection = database[files_name] end |
インスタンス属性の詳細
# chunks_collection =コレクション(読み取り専用)
chunks_collection チャンク コレクションを返します。
88 89 90 |
ファイル 'lib/mongo/ Grid/fs_bucket.rb '、行 88 デフォルト chunks_collection @chunks_collection end |
#database ⇒ Database (readonly)
データベース データベースを返します。
93 94 95 |
ファイル 'lib/mongo/ Grid/fs_bucket.rb '、行 93 デフォルト database @database end |
#files_collection ~コレクション(読み取り専用)
ファイル_コレクション のファイル コレクションを返します。
98 99 100 |
ファイル 'lib/mongo/ Grid/fs_bucket.rb '、行 98 デフォルト ファイル_コレクション @files_collection end |
オプション=ハッシュ(読み取り専用)
オプション FSbucket オプションを返します。
103 104 105 |
ファイル 'lib/mongo/ Grid/fs_bucket.rb '、行 103 デフォルト @options end |
インスタンス メソッドの詳細
delete (ID, opts = {}) = 結果 = 結果
ID で識別される単一のファイルを GridFS から削除します。
220 221 222 223 224 225 226 227 228 229 230 |
ファイル 'lib/mongo/ Grid/fs_bucket.rb '、行 220 デフォルト 削除(id, ops = {}) timeout_holder = CsonTimeoutH older.新着情報(operation_timeouts: operation_timeouts(ops)) 結果 = ファイル_コレクション .find({ :_id => id }, @options.merge(timeout_ms: timeout_holder.retention_timeout_ms)) .delete_one(timeout_ms: timeout_holder.retention_timeout_ms) chunks_collection .find({ :files_id => id }, @options.merge(timeout_ms: timeout_holder.retention_timeout_ms)) .delete_many(timeout_ms: timeout_holder.retention_timeout_ms) 発生 エラー::ファイルではない.新着情報(id, :id) 場合 結果.n == 0 結果 end |
# delete_one (ファイル, opts = {}) = 結果 = 結果
GridFS から単一ファイルを削除します。
204 205 206 |
ファイル 'lib/mongo/ Grid/fs_bucket.rb '、行 204 デフォルト delete_one(ファイル, ops = {}) 削除(ファイル.id, ops) end |
ダウンロード_to_stream ( ID , io) =オブジェクト
ID で指定されたファイルの内容をダウンロードし、宛先 io オブジェクトに書込みます。
271 272 273 274 275 276 277 |
ファイル 'lib/mongo/ Grid/fs_bucket.rb '、行 271 デフォルト ダウンロード_to_ストリーム(id, io) open_ダウンロード_ストリーム(id) 行う |ストリーム| ストリーム.各 行う |チャンク| io < チャンク end end end |
ダウンロード_to_stream_by_name(ファイル名, io, opts = {}) =オブジェクト
ファイル名とオプションの 変更によって指定された保存済みファイルの内容をダウンロードし、その内容を宛先 io オブジェクトに書込みます。
Revision numbers are defined as follows: 0 = the original stored file 1 = the first revision 2 = the second revision etc…-2 = the second most recent revision -1 = the most recent revision
# @example 元のファイルをダウンロードします。
fs.download_to_stream_by_name('some-file.txt', io, revision: 0)
364 365 366 |
ファイル 'lib/mongo/ Grid/fs_bucket.rb '、行 364 デフォルト ダウンロード_to_stream_by_name(ファイル名, io, ops = {}) ダウンロード_to_ストリーム(open_Download_stream_by_name(ファイル名, ops).file_id, io) end |
#drop(ops = {}) = オブジェクト
このバケット を実装するコレクションを削除します。
493 494 495 496 497 |
ファイル 'lib/mongo/ Grid/fs_bucket.rb '、行 493 デフォルト drop(ops = {}) context = 操作::Context.新着情報(operation_timeouts: operation_timeouts(ops)) ファイル_コレクション.drop(timeout_ms: context.retention_timeout_ms) chunks_collection.drop(timeout_ms: context.retention_timeout_ms) end |
# find (Selector = nil、Options = {}) = CollectionView
指定されたセレクターに一致するファイル コレクション ドキュメントを検索します。
134 135 136 137 |
ファイル 'lib/mongo/ Grid/fs_bucket.rb '、行 134 デフォルト find(セレクター = nil, = {}) ops = .merge(read: read_preference) 場合 read_preference ファイル_コレクション.find(セレクター, ops || ) end |
# find_one (Selector = nil) = Grid::File
代わりに - 1の制限で #find を使用してください。 バージョン3.0で削除されます。
GridFS 内のファイルを検索します。
155 156 157 158 159 160 |
ファイル 'lib/mongo/ Grid/fs_bucket.rb '、行 155 デフォルト find_one(セレクター = nil) file_info = ファイル_コレクション.find(セレクター).最初に return nil ただし、 file_info チャンク = chunks_collection.find(:files_id => file_info[:_id]).sort(:n => 1) グリッド::ファイル.新着情報(チャンク.to_a, オプション::マッパー.transform(file_info, グリッド::ファイル::info::mappings.invert)) end |
#insert_one(file) ⇒ BSON::ObjectId
代わりに、#upload_from_stream または #open_upload_stream を使用してください。 バージョン3.0で削除されます。
GridFS に単一のファイルを挿入します。
175 176 177 178 179 180 |
ファイル 'lib/mongo/ Grid/fs_bucket.rb '、行 175 デフォルト insert_one(ファイル) @indexes ||= ensure_indexes! chunks_collection.insert_many(ファイル.チャンク) ファイル_コレクション.insert_one(ファイル.info) ファイル.id end |
#open_Download_stream ( ID 、オプション = nil){{|The| ... } = Stream::Read
ID で指定されたファイルをダウンロードできるストリームを開きます。
248 249 250 251 252 253 254 255 256 257 258 259 |
ファイル 'lib/mongo/ Grid/fs_bucket.rb '、行 248 デフォルト open_ダウンロード_ストリーム(id, = nil) = Utils.slow_symbols_keys( || {}) read_stream(id, **).タップ 行う |ストリーム| 場合 ブロック_指定 begin ノードの数 ストリーム 保証する ストリーム.閉じる end end end end |
#open_Download_stream_by_name (ファイル名、opts = {}){{|The| ... } = Stream::Read
アプリケーションがファイル名で指定された保存済みファイルの内容と オプションのリダイレクトを読み取ることができるストリームを開きます。
Revision numbers are defined as follows: 0 = the original stored file 1 = the first revision 2 = the second revision etc…-2 = the second most recent revision -1 = the most recent revision
# @example ストリームを開き、元のファイルをダウンロードします。
fs.open_download_stream_by_name('some-file.txt', revision: 0)
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
ファイル 'lib/mongo/ Grid/fs_bucket.rb '、行 313 デフォルト open_Download_stream_by_name(ファイル名, ops = {}, &ブロック) 改訂 = ops.fetch(:regation, -1) 場合 改訂 < 0 スキップ = 改訂.abs - 1 sort = { ' loupDate ' => mongo::Index::下降 } else スキップ = 改訂 sort = { ' loupDate ' => mongo::Index::上昇 } end file_info_doc = ファイル_コレクション.find({ ファイル名: ファイル名} , sort: sort, skip: スキップ, limit: -1).最初に ただし、 file_info_doc 発生 エラー::ファイルではない.新着情報(ファイル名, :filename) ただし、 ops[:regation] 発生 エラー::InvalidFileRevision.新着情報(ファイル名, ops[:regation]) end open_ダウンロード_ストリーム(file_info_doc[:_id], file_info_doc: file_info_doc, &ブロック) end |
#open_upload_stream (ファイル名、opts ={{}){{|The| ... } = Stream::Write
ファイルまたは long の内容を書き込むことができる GridFS へのアップロードストリームを開きます。
394 395 396 397 398 399 400 401 402 403 404 405 |
ファイル 'lib/mongo/ Grid/fs_bucket.rb '、行 394 デフォルト open_upload_stream(ファイル名, ops = {}) ops = Utils.slow_symbols_keys(ops) write_stream(ファイル名, **ops).タップ 行う |ストリーム| 場合 ブロック_指定 begin ノードの数 ストリーム 保証する ストリーム.閉じる end end end end |
# prefix = string
GridFS のプレフィックスを取得する
190 191 192 |
ファイル 'lib/mongo/ Grid/fs_bucket.rb '、行 190 デフォルト prefix @options[:fs_name] || @options[:bucket_name] || DEFAULT_ROOT end |
#read_preference = BSON::Document
このメソッドは常に BSON::Document インスタンスを返します。ただし、FSbucket コンストラクターは :read のタイプを BSON::Document ではなくハッシュとして指定しているにもかかわらず
読み込み設定 (read preference) を取得します。
465 466 467 468 469 470 471 472 473 474 |
ファイル 'lib/mongo/ Grid/fs_bucket.rb '、行 465 デフォルト read_preference @read_preference ||= begin pref = [:read] || database.read_preference 場合 BSON::ドキュメント === pref pref else BSON::ドキュメント.新着情報(pref) end end end |
#upload_from_stream(filename, io, opts = {}) ⇒ BSON::ObjectId
ユーザー ファイルを GridFS バケットにアップロードします。 ソース ストリームからユーザー ファイルの内容を読み取り、 チャンク コレクションにチャンクとしてアップロードします。 すべてのチャンクがアップロードされると、 ファイル コレクション内のファイル名用の ファイル コレクション ドキュメントが作成されます。
435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 |
ファイル 'lib/mongo/ Grid/fs_bucket.rb '、行 435 デフォルト return_from_stream(ファイル名, io, ops = {}) open_upload_stream(ファイル名, ops) 行う |ストリーム| begin ストリーム.書込み (write)(io) # IOError と SystemCallError は、io の読み取りエラー用です。 # Error::SocketError と Error::SocketTimeoutError は MongoDB への 書込み (write)。 ヘルプ IOError, SystemCallError, エラー::SocketError, エラー::SocketTimeoutError begin ストリーム.中止 ヘルプ エラー::OperationFailure end 発生 end end.file_id end |
#write_concern = Mongo::WriteConcern
書込み保証 (write concern) を取得します。
484 485 486 487 488 489 490 |
ファイル 'lib/mongo/ Grid/fs_bucket.rb '、行 484 デフォルト write_concern @write_concern ||= 場合 wco = @options[:write_concern] || @options[:write] WriteConcern.得る(wco) else database.write_concern end end |