#mongo-db #storage #remi #logging-tracing #storage-api #applications #grid-fs

remi-gridfs

๐Ÿปโ€โ„๏ธ๐Ÿงถ Official and maintained remi-rs crate for support of MongoDB GridFS

20 releases (9 breaking)

0.10.0 Dec 4, 2024
0.9.1 Oct 21, 2024
0.8.1 Oct 17, 2024
0.8.0 May 24, 2024
0.1.0 Feb 9, 2023

#1505 in Database interfaces

Download history 66/week @ 2024-08-19 32/week @ 2024-08-26 8/week @ 2024-09-02 16/week @ 2024-09-09 211/week @ 2024-09-16 92/week @ 2024-09-23 94/week @ 2024-09-30 20/week @ 2024-10-07 354/week @ 2024-10-14 394/week @ 2024-10-21 30/week @ 2024-10-28 137/week @ 2024-11-04 74/week @ 2024-11-11 25/week @ 2024-11-18 28/week @ 2024-11-25 199/week @ 2024-12-02

328 downloads per month

MIT license

57KB
586 lines

Official and maintained remi-rs crate for support of MongoDB GridFS

v0.10.0 | ๐Ÿ“œ Documentation
Crate Features Description Enabled by default?
export-crates Exports all the used MongoDB crates as a module called mongodb Yes.
unstable Tap into unstable features from remi_gridfs and the remi crate. No.
tracing Enables the use of tracing::instrument and emit events for actions by the crate. No.
serde Enables the use of serde in StorageConfig No.
log Emits log records for actions by the crate No.

Example

// Cargo.toml:
//
// [dependencies]
// remi = "^0"
// remi-gridfs = { version = "^0", features = ["export-crates"] }
// tokio = { version = "^1", features = ["full"] }

use remi_gridfs::{StorageService, StorageConfig, mongodb};
use remi::{StorageService as _, UploadRequest};

#[tokio::main]
async fn main() {
    let storage = StorageService::from_conn_string("mongodb://localhost:27017", StorageConfig {
        bucket: "my-bucket".into(),

        ..Default::default()
    }).await.unwrap();

    // Initialize the container. This will:
    //
    // * create the `my-bucket` GridFS bucket if it doesn't exist
    storage.init().await.unwrap();

    // Now we can upload files to GridFS.

    // We define a `UploadRequest`, which will set the content type to `text/plain` and set the
    // contents of `weow.txt` to `weow fluff`.
    let upload = UploadRequest::default()
        .with_content_type(Some("text/plain"))
        .with_data("weow fluff");

    // Let's upload it!
    storage.upload("weow.txt", upload).await.unwrap();

    // Let's check if it exists! This `assert!` will panic if it failed
    // to upload.
    assert!(storage.exists("weow.txt").await.unwrap());
}

Dependencies

~15โ€“25MB
~379K SLoC