5 releases

0.2.2 Jan 13, 2024
0.2.1 Dec 28, 2023
0.2.0 Nov 2, 2023
0.1.1 Nov 2, 2023
0.1.0 Nov 2, 2023

#959 in Rust patterns

Download history 15/week @ 2024-01-12 19/week @ 2024-01-19 1/week @ 2024-01-26 6/week @ 2024-02-02 14/week @ 2024-02-09 15/week @ 2024-02-16 41/week @ 2024-02-23 10/week @ 2024-03-01 4/week @ 2024-03-15 4/week @ 2024-03-22 25/week @ 2024-03-29 29/week @ 2024-04-05 17/week @ 2024-04-12 9/week @ 2024-04-19

80 downloads per month

GPL-3.0-or-later

8KB
151 lines

Configure mongo indexing right on your rust structs

Example

use serde::{Serialize, Deserialize};
use mongo_indexed::{derive::MongoIndexed, Indexed};
use mongodb::bson::doc;

#[derive(Serialize, Deserialize, MongoIndexed)]
#[unique_doc_index(doc! { "username": 1, "email": 1 })]
pub struct User {
  #[serde(rename = "_id")]
  pub id: ObjectId,
  
  #[index]
  pub username: String,

  #[index]
  pub email: String,
}

// Use the collection initializer

#[tokio::main]
async fn main() -> anyhow::Result<()> {
  let mongo = ... // init mongodb::Client

  let create_index = true;

  let users = User::collection(&mongo, "db_name", create_index).await?; // mongodb::Collection<User>

  // use the indexed collection...

  Ok(())
}

Dependencies

~25–37MB
~753K SLoC