Struct mongodb_gridfs::bucket::GridFSBucket[][src]

pub struct GridFSBucket { /* fields omitted */ }
Expand description

GridFS bucket. A prefix under which a GridFS system’s collections are stored. Spec

Implementations

impl GridFSBucket[src]

pub async fn delete(&self, id: ObjectId) -> Result<(), GridFSError>[src]

Given a @id, delete this stored file’s files collection document and associated chunks from a GridFS bucket. Spec

 use mongodb_gridfs::{GridFSBucket, GridFSError};
 let bucket = GridFSBucket::new(db.clone(), Some(GridFSBucketOptions::default()));
 bucket.delete(id).await?;

Errors

Raise GridFSError::FileNotFound when the requested id doesn’t exists.

impl GridFSBucket[src]

pub async fn open_download_stream(
    &self,
    id: ObjectId
) -> Result<impl Stream<Item = Vec<u8>>, GridFSError>
[src]

Opens a Stream from which the application can read the contents of the stored file specified by @id. Spec

Returns a [Stream].

Examples

use futures::stream::StreamExt;
use mongodb_gridfs::{options::GridFSBucketOptions, GridFSBucket, GridFSError};
let bucket = GridFSBucket::new(db.clone(), Some(GridFSBucketOptions::default()));
let mut cursor = bucket.open_download_stream(id).await?;
let buffer = cursor.next().await.unwrap();

Errors

Raise GridFSError::FileNotFound when the requested id doesn’t exists.

impl GridFSBucket[src]

pub async fn drop(&self) -> Result<()>[src]

Drops the files and chunks collections associated with this bucket. Spec

impl GridFSBucket[src]

pub async fn find(
    &self,
    filter: Document,
    options: GridFSFindOptions
) -> Result<Cursor>
[src]

Find and return the files collection documents that match @filter. Spec

Examples

use bson::doc;
use futures::stream::StreamExt;
use mongodb_gridfs::{bucket::GridFSBucket, options::GridFSFindOptions};

let mut cursor = bucket
        .find(doc! {"filename":"test.txt"}, GridFSFindOptions::default())
        .await?;

    while let Some(_doc) = cursor.next().await {
        // ...
    }

impl GridFSBucket[src]

pub async fn rename(
    &self,
    id: ObjectId,
    new_filename: &str
) -> Result<UpdateResult>
[src]

Renames the stored file with the specified @id. Spec

impl GridFSBucket[src]

pub async fn upload_from_stream(
    self,
    filename: &str,
    source: impl Read,
    options: Option<GridFSUploadOptions>
) -> Result<ObjectId, Error>
[src]

Uploads a user file to a GridFS bucket. The driver generates the file id.

Reads the contents of the user file from the @source Stream and uploads it as chunks in the chunks collection. After all the chunks have been uploaded, it creates a files collection document for @filename in the files collection.

Returns the id of the uploaded file.

Note: this method is provided for backward compatibility. In languages that use generic type parameters, this method may be omitted since the TFileId type might not be an ObjectId.

Examples

use mongodb_gridfs::{options::GridFSBucketOptions, GridFSBucket};
let bucket = GridFSBucket::new(db.clone(), Some(GridFSBucketOptions::default()));
let id = bucket
    .upload_from_stream("test.txt", "stream your data here".as_bytes(), None)
    .await?;

impl GridFSBucket[src]

pub fn new(db: Database, options: Option<GridFSBucketOptions>) -> GridFSBucket[src]

Create a new GridFSBucket object on @db with the given @options.

Trait Implementations

impl Clone for GridFSBucket[src]

fn clone(&self) -> GridFSBucket[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for GridFSBucket[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T> Instrument for T[src]

fn instrument(self, span: Span) -> Instrumented<Self>[src]

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

fn in_current_span(self) -> Instrumented<Self>[src]

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

impl<T> Instrument for T[src]

fn instrument(self, span: Span) -> Instrumented<Self>[src]

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

fn in_current_span(self) -> Instrumented<Self>[src]

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

Creates owned data from borrowed data, usually by cloning. Read more

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 

pub fn vzip(self) -> V