Loading...
Searching...
No Matches
mongocxx::v1::gridfs::bucket Class Reference

`#include <mongocxx/v1/gridfs/bucket.hpp>`

## Description

A GridFS bucket.

See also
  - GridFS (MongoDB Manual)

## Classes

class | options
| Options for mongocxx::v1::gridfs::bucket. More...

## Public Types

enum class | errc
| Errors codes which may be returned by mongocxx::v1::gridfs::bucket. More...

## Public Member Functions

| bucket ()
| Default initialization.
| bucket (bucket &&other) noexcept
| Move constructor.
| bucket (bucket const &other)
| Copy construction.
| ~bucket ()
| Destroy this object.
bsoncxx::v1::stdx::string_view | bucket_name () const
| Return the name of this bucket.
| operator bool () const
| Return true when *this is NOT in an assign-or-destroy-only state.
bucket & | operator= (bucket &&other) noexcept
| Move assignment.
bucket & | operator= (bucket const &other)
| Copy assignment.
v1::gridfs::uploader | open_upload_stream (bsoncxx::v1::stdx::string_view filename, v1::gridfs::upload_options const &opts={})
| Equivalent to open_upload_stream_with_id with a file ID generated using bsoncxx::v1::oid.
v1::gridfs::uploader | open_upload_stream (v1::client_session const &session, bsoncxx::v1::stdx::string_view filename, v1::gridfs::upload_options const &opts={})
| Equivalent to open_upload_stream_with_id with a file ID generated using bsoncxx::v1::oid.
v1::gridfs::uploader | open_upload_stream_with_id (bsoncxx::v1::types::view id, bsoncxx::v1::stdx::string_view filename, v1::gridfs::upload_options const &opts={})
| Return an uploader for a new file to this bucket.
v1::gridfs::uploader | open_upload_stream_with_id (v1::client_session const &session, bsoncxx::v1::types::view id, bsoncxx::v1::stdx::string_view filename, v1::gridfs::upload_options const &opts={})
| Return an uploader for a new file to this bucket.
v1::gridfs::upload_result | upload_from_stream (bsoncxx::v1::stdx::string_view filename, std::istream &input, v1::gridfs::upload_options const &opts={})
| Equivalent to upload_from_stream_with_id with a file ID generated using bsoncxx::v1::oid.
v1::gridfs::upload_result | upload_from_stream (v1::client_session const &session, bsoncxx::v1::stdx::string_view filename, std::istream &input, v1::gridfs::upload_options const &opts={})
| Equivalent to upload_from_stream_with_id with a file ID generated using bsoncxx::v1::oid.
void | upload_from_stream_with_id (bsoncxx::v1::types::view id, bsoncxx::v1::stdx::string_view filename, std::istream &input, v1::gridfs::upload_options const &opts={})
| Upload the contents of input as a new file to this bucket.
void | upload_from_stream_with_id (v1::client_session const &session, bsoncxx::v1::types::view id, bsoncxx::v1::stdx::string_view filename, std::istream &input, v1::gridfs::upload_options const &opts={})
| Upload the contents of input as a new file to this bucket.
v1::gridfs::downloader | open_download_stream (bsoncxx::v1::types::view id)
| Return a downloader for the requested file from this bucket.
v1::gridfs::downloader | open_download_stream (v1::client_session const &session, bsoncxx::v1::types::view id)
| Return a downloader for the requested file from this bucket.
void | download_to_stream (bsoncxx::v1::types::view id, std::ostream &output)
| Download the entire contents of the requested file from this bucket into output.
void | download_to_stream (v1::client_session const &session, bsoncxx::v1::types::view id, std::ostream &output)
| Download the entire contents of the requested file from this bucket into output.
void | download_to_stream (bsoncxx::v1::types::view id, std::ostream &output, std::size_t start, std::size_t end)
| Partially download the contents of the requested file from this bucket into output.
void | download_to_stream (v1::client_session const &session, bsoncxx::v1::types::view id, std::ostream &output, std::size_t start, std::size_t end)
| Partially download the contents of the requested file from this bucket into output.
void | delete_file (bsoncxx::v1::types::view id)
| Delete the requested file from this bucket.
void | delete_file (v1::client_session const &session, bsoncxx::v1::types::view id)
| Delete the requested file from this bucket.
v1::cursor | find (bsoncxx::v1::document::view filter, v1::find_options const &opts={})
| Find files within this bucket matching the given query filter.
v1::cursor | find (v1::client_session const &session, bsoncxx::v1::document::view filter, v1::find_options const &opts={})
| Find files within this bucket matching the given query filter.

## Static Public Member Functions

static std::error_category const & | error_category ()
| The error category for mongocxx::v1::gridfs::bucket::errc.

## Friends

std::error_code | make_error_code (errc v)
| Support implicit conversion to std::error_code.

## Member Enumeration Documentation

## errc

enum class mongocxx::v1::gridfs::bucket::errc

strong

Errors codes which may be returned by mongocxx::v1::gridfs::bucket.

Enumerator
zero | Zero.
invalid_bucket_name | The "bucketName" field must not be empty.
invalid_chunk_size_bytes | The "chunkSizeBytes" field must be a positive value.
not_found | The requested GridFS file does not exist.
corrupt_data | The GridFS file is in an invalid or inconsistent state.
invalid_byte_range | [start, end) must be a valid range of byte indexes within the requested GridFS file.

## Constructor & Destructor Documentation

## ~bucket()

mongocxx::v1::gridfs::bucket::~bucket | ( |  | ) |

Destroy this object.

Warning
  Invalidates all associated views.

## bucket() [1/3]

mongocxx::v1::gridfs::bucket::bucket | ( | bucket && | other | ) |

noexcept

Move constructor.

Postconditions:
  - other is in an assign-or-destroy-only state.

## bucket() [2/3]

mongocxx::v1::gridfs::bucket::bucket | ( | bucket const & | other | ) |

Copy construction.

## bucket() [3/3]

mongocxx::v1::gridfs::bucket::bucket | ( |  | ) |

Default initialization.

Postconditions:
  - *this is in an assign-or-destroy-only state.

## Member Function Documentation

## bucket_name()

bsoncxx::v1::stdx::string_view mongocxx::v1::gridfs::bucket::bucket_name | ( |  | ) | const

Return the name of this bucket.

## delete_file() [1/2]

void mongocxx::v1::gridfs::bucket::delete_file | ( | bsoncxx::v1::types::view | id | ) |

Delete the requested file from this bucket.

Exceptions

  mongocxx::v1::exception | with mongocxx::v1::gridfs::bucket::errc::not_found if the requested file does not exist.
  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

## delete_file() [2/2]

void mongocxx::v1::gridfs::bucket::delete_file | ( | v1::client_session const & | session,
|  | bsoncxx::v1::types::view | id )

Delete the requested file from this bucket.

Exceptions

  mongocxx::v1::exception | with mongocxx::v1::gridfs::bucket::errc::not_found if the requested file does not exist.
  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

## download_to_stream() [1/4]

void mongocxx::v1::gridfs::bucket::download_to_stream | ( | bsoncxx::v1::types::view | id,
|  | std::ostream & | output )

Download the entire contents of the requested file from this bucket into output.

Exceptions

  mongocxx::v1::exception | with mongocxx::v1::gridfs::bucket::errc::not_found if the requested file does not exist.
  mongocxx::v1::exception | with mongocxx::v1::gridfs::bucket::errc::corrupt_data if the GridFS file data is invalid or inconsistent.
  std::ios_base::failure | if an error is encountered when writing to output.
  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

## download_to_stream() [2/4]

void mongocxx::v1::gridfs::bucket::download_to_stream | ( | bsoncxx::v1::types::view | id,
|  | std::ostream & | output,
|  | std::size_t | start,
|  | std::size_t | end )

Partially download the contents of the requested file from this bucket into output.

Exceptions

  mongocxx::v1::exception | with mongocxx::v1::gridfs::bucket::errc::not_found if the requested file does not exist.
  mongocxx::v1::exception | with mongocxx::v1::gridfs::bucket::errc::corrupt_data if the GridFS file data is invalid or inconsistent.
  std::ios_base::failure | if an error is encountered when writing to output.
  mongocxx::v1::exception | with mongocxx::v1::gridfs::bucket::errc::invalid_byte_range if [start, end) is not a valid range of byte indexes within the requested file.
  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

## download_to_stream() [3/4]

void mongocxx::v1::gridfs::bucket::download_to_stream | ( | v1::client_session const & | session,
|  | bsoncxx::v1::types::view | id,
|  | std::ostream & | output )

Download the entire contents of the requested file from this bucket into output.

Exceptions

  mongocxx::v1::exception | with mongocxx::v1::gridfs::bucket::errc::not_found if the requested file does not exist.
  mongocxx::v1::exception | with mongocxx::v1::gridfs::bucket::errc::corrupt_data if the GridFS file data is invalid or inconsistent.
  std::ios_base::failure | if an error is encountered when writing to output.
  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

## download_to_stream() [4/4]

void mongocxx::v1::gridfs::bucket::download_to_stream | ( | v1::client_session const & | session,
|  | bsoncxx::v1::types::view | id,
|  | std::ostream & | output,
|  | std::size_t | start,
|  | std::size_t | end )

Partially download the contents of the requested file from this bucket into output.

Exceptions

  mongocxx::v1::exception | with mongocxx::v1::gridfs::bucket::errc::not_found if the requested file does not exist.
  mongocxx::v1::exception | with mongocxx::v1::gridfs::bucket::errc::corrupt_data if the GridFS file data is invalid or inconsistent.
  std::ios_base::failure | if an error is encountered when writing to output.
  mongocxx::v1::exception | with mongocxx::v1::gridfs::bucket::errc::invalid_byte_range if [start, end) is not a valid range of byte indexes within the requested file.
  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

## error_category()

std::error_category const & mongocxx::v1::gridfs::bucket::error_category | ( |  | ) |

static

The error category for mongocxx::v1::gridfs::bucket::errc.

## find() [1/2]

v1::cursor mongocxx::v1::gridfs::bucket::find | ( | bsoncxx::v1::document::view | filter,
|  | v1::find_options const & | opts = {} )

Find files within this bucket matching the given query filter.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

## find() [2/2]

v1::cursor mongocxx::v1::gridfs::bucket::find | ( | v1::client_session const & | session,
|  | bsoncxx::v1::document::view | filter,
|  | v1::find_options const & | opts = {} )

Find files within this bucket matching the given query filter.

Exceptions

  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

## open_download_stream() [1/2]

v1::gridfs::downloader mongocxx::v1::gridfs::bucket::open_download_stream | ( | bsoncxx::v1::types::view | id | ) |

Return a downloader for the requested file from this bucket.

Exceptions

  mongocxx::v1::exception | with mongocxx::v1::gridfs::bucket::errc::not_found if the requested file does not exist.
  mongocxx::v1::exception | with mongocxx::v1::gridfs::bucket::errc::corrupt_data if the GridFS file data is invalid or inconsistent.
  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

## open_download_stream() [2/2]

v1::gridfs::downloader mongocxx::v1::gridfs::bucket::open_download_stream | ( | v1::client_session const & | session,
|  | bsoncxx::v1::types::view | id )

Return a downloader for the requested file from this bucket.

Exceptions

  mongocxx::v1::exception | with mongocxx::v1::gridfs::bucket::errc::not_found if the requested file does not exist.
  mongocxx::v1::exception | with mongocxx::v1::gridfs::bucket::errc::corrupt_data if the GridFS file data is invalid or inconsistent.
  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

## open_upload_stream() [1/2]

v1::gridfs::uploader mongocxx::v1::gridfs::bucket::open_upload_stream | ( | bsoncxx::v1::stdx::string_view | filename,
|  | v1::gridfs::upload_options const & | opts = {} )

Equivalent to open_upload_stream_with_id with a file ID generated using bsoncxx::v1::oid.

## open_upload_stream() [2/2]

v1::gridfs::uploader mongocxx::v1::gridfs::bucket::open_upload_stream | ( | v1::client_session const & | session,
|  | bsoncxx::v1::stdx::string_view | filename,
|  | v1::gridfs::upload_options const & | opts = {} )

Equivalent to open_upload_stream_with_id with a file ID generated using bsoncxx::v1::oid.

## open_upload_stream_with_id() [1/2]

v1::gridfs::uploader mongocxx::v1::gridfs::bucket::open_upload_stream_with_id | ( | bsoncxx::v1::types::view | id,
|  | bsoncxx::v1::stdx::string_view | filename,
|  | v1::gridfs::upload_options const & | opts = {} )

Return an uploader for a new file to this bucket.

Note
  The file is not completely uploaded until mongocxx::v1::gridfs::uploader::close() is invoked.

Exceptions

  mongocxx::v1::exception | with mongocxx::v1::gridfs::bucket::errc::invalid_chunk_size_bytes if the "chunkSizeBytes" field is not a positive value.
  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

## open_upload_stream_with_id() [2/2]

v1::gridfs::uploader mongocxx::v1::gridfs::bucket::open_upload_stream_with_id | ( | v1::client_session const & | session,
|  | bsoncxx::v1::types::view | id,
|  | bsoncxx::v1::stdx::string_view | filename,
|  | v1::gridfs::upload_options const & | opts = {} )

Return an uploader for a new file to this bucket.

Note
  The file is not completely uploaded until mongocxx::v1::gridfs::uploader::close() is invoked.

Exceptions

  mongocxx::v1::exception | with mongocxx::v1::gridfs::bucket::errc::invalid_chunk_size_bytes if the "chunkSizeBytes" field is not a positive value.
  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

## operator bool()

mongocxx::v1::gridfs::bucket::operator bool | ( |  | ) | const

explicit

Return true when *this is NOT in an assign-or-destroy-only state.

## operator=() [1/2]

bucket & mongocxx::v1::gridfs::bucket::operator= | ( | bucket && | other | ) |

noexcept

Move assignment.

Postconditions:
  - other is in an assign-or-destroy-only state.

## operator=() [2/2]

bucket & mongocxx::v1::gridfs::bucket::operator= | ( | bucket const & | other | ) |

Copy assignment.

## upload_from_stream() [1/2]

v1::gridfs::upload_result mongocxx::v1::gridfs::bucket::upload_from_stream | ( | bsoncxx::v1::stdx::string_view | filename,
|  | std::istream & | input,
|  | v1::gridfs::upload_options const & | opts = {} )

Equivalent to upload_from_stream_with_id with a file ID generated using bsoncxx::v1::oid.

## upload_from_stream() [2/2]

v1::gridfs::upload_result mongocxx::v1::gridfs::bucket::upload_from_stream | ( | v1::client_session const & | session,
|  | bsoncxx::v1::stdx::string_view | filename,
|  | std::istream & | input,
|  | v1::gridfs::upload_options const & | opts = {} )

Equivalent to upload_from_stream_with_id with a file ID generated using bsoncxx::v1::oid.

## upload_from_stream_with_id() [1/2]

void mongocxx::v1::gridfs::bucket::upload_from_stream_with_id | ( | bsoncxx::v1::types::view | id,
|  | bsoncxx::v1::stdx::string_view | filename,
|  | std::istream & | input,
|  | v1::gridfs::upload_options const & | opts = {} )

Upload the contents of input as a new file to this bucket.

Exceptions

  std::ios_base::failure | if an error is encountered when reading from input.
  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

## upload_from_stream_with_id() [2/2]

void mongocxx::v1::gridfs::bucket::upload_from_stream_with_id | ( | v1::client_session const & | session,
|  | bsoncxx::v1::types::view | id,
|  | bsoncxx::v1::stdx::string_view | filename,
|  | std::istream & | input,
|  | v1::gridfs::upload_options const & | opts = {} )

Upload the contents of input as a new file to this bucket.

Exceptions

  std::ios_base::failure | if an error is encountered when reading from input.
  mongocxx::v1::server_error | when a server-side error is encountered and a raw server error is available.
  mongocxx::v1::exception | for all other runtime errors.

## Friends And Related Symbol Documentation

## make_error_code

std::error_code make_error_code | ( | errc | v | ) |

friend

Support implicit conversion to std::error_code.

The documentation for this class was generated from the following file:

- mongocxx/v1/gridfs/bucket.hpp