ODM for MongoDB based on Mongoose and written in Rust
```rust use nongoose::{bson::oid::ObjectId, Client, Schema}; use serde::{Deserialize, Serialize};
struct User { #[schema(id)] #[serde(rename = "_id")] pub id: ObjectId,
#[schema(unique)] pub username: String, }
async fn main() { // Get MongoDB connection. let client = match Client::withuristr("mongodb://localhost:27017").await { Ok(client) => client, Err(e) => panic!("Error connecting to the database: {}", e), };
// Nongoose instance.
let nongoose = nongoose::Nongoose::build(client.database("nextchat"))
.add_schema::
let user = User { id: ObjectId::new(), username: String::from("nongoose"), };
if let Err(error) = user.save().await { panic!("Cannot create the user: {}", error); }
println!("User created in the database: {}", user.id); } ```
```sh
$ DATABASE_URL=mongodb://localhost:27017 cargo test --no-default-features --features derive,sync
$ DATABASE_URL=mongodb://localhost:27017 cargo test ```
Check the COPYING file for more information.
Thanks to this amazing people for make Nongoose better:
If you help to Nongoose feel free to add here.