{"id":20029511,"url":"https://github.com/http-rs/async-mongodb-session","last_synced_at":"2025-05-05T03:32:26.718Z","repository":{"id":40496133,"uuid":"282245668","full_name":"http-rs/async-mongodb-session","owner":"http-rs","description":"An async-session implementation for MongoDB","archived":false,"fork":false,"pushed_at":"2022-08-21T18:49:31.000Z","size":58,"stargazers_count":17,"open_issues_count":0,"forks_count":7,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-15T17:07:54.608Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/http-rs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":null,"license":"LICENSE-APACHE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-24T14:50:09.000Z","updated_at":"2024-10-28T13:22:44.000Z","dependencies_parsed_at":"2022-08-09T22:13:17.412Z","dependency_job_id":null,"html_url":"https://github.com/http-rs/async-mongodb-session","commit_stats":null,"previous_names":["yoshuawuyts/async-mongodb-session"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/http-rs%2Fasync-mongodb-session","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/http-rs%2Fasync-mongodb-session/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/http-rs%2Fasync-mongodb-session/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/http-rs%2Fasync-mongodb-session/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/http-rs","download_url":"https://codeload.github.com/http-rs/async-mongodb-session/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252435278,"owners_count":21747384,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T09:20:40.478Z","updated_at":"2025-05-05T03:32:26.366Z","avatar_url":"https://github.com/http-rs.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003easync-mongodb-session\u003c/h1\u003e\n\u003cdiv align=\"center\"\u003e\n  \u003cstrong\u003e\n    An async-session implementation for MongoDB\n  \u003c/strong\u003e\n\u003c/div\u003e\n\n\u003cbr /\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003c!-- Crates version --\u003e\n  \u003ca href=\"https://crates.io/crates/async-mongodb-session\"\u003e\n    \u003cimg src=\"https://img.shields.io/crates/v/async-mongodb-session.svg?style=flat-square\"\n    alt=\"Crates.io version\" /\u003e\n  \u003c/a\u003e\n  \u003c!-- Downloads --\u003e\n  \u003ca href=\"https://crates.io/crates/async-mongodb-session\"\u003e\n    \u003cimg src=\"https://img.shields.io/crates/d/async-mongodb-session.svg?style=flat-square\"\n      alt=\"Download\" /\u003e\n  \u003c/a\u003e\n  \u003c!-- docs.rs docs --\u003e\n  \u003ca href=\"https://docs.rs/async-mongodb-session\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/docs-latest-blue.svg?style=flat-square\"\n      alt=\"docs.rs docs\" /\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003ch3\u003e\n    \u003ca href=\"https://docs.rs/async-mongodb-session\"\u003e\n      API Docs\n    \u003c/a\u003e\n    \u003cspan\u003e | \u003c/span\u003e\n    \u003ca href=\"https://github.com/yoshuawuyts/async-mongodb-session/releases\"\u003e\n      Releases\n    \u003c/a\u003e\n    \u003cspan\u003e | \u003c/span\u003e\n    \u003ca href=\"https://github.com/yoshuawuyts/async-mongodb-session/blob/master.github/CONTRIBUTING.md\"\u003e\n      Contributing\n    \u003c/a\u003e\n  \u003c/h3\u003e\n\u003c/div\u003e\n\n## Installation\n```sh\n$ cargo add async-mongodb-session\n```\n\n## Overview\nThis library utilises the document expiration feature in mongodb and is based on [specific clock time](https://docs.mongodb.com/manual/tutorial/expire-data/#expire-documents-at-a-specific-clock-time).\n\nThe expiry index is applied to the collection when a new session object is created. \n\nAs document expiration is a [background task](https://docs.mongodb.com/manual/core/index-ttl/#timing-of-the-delete-operation) some stale sessions may be present in the database but won't be returned by this library.\n\n## Example with tide\nCreate an HTTP server that keep track of user visits in the session.\n\n```rust\n#[async_std::main]\nasync fn main() -\u003e tide::Result\u003c()\u003e {\n    tide::log::start();\n    let mut app = tide::new();\n\n    app.with(tide::sessions::SessionMiddleware::new(\n        MongodbSessionStore::new(\"mongodb://127.0.0.1:27017\", \"db_name\", \"collection\").await?,\n        std::env::var(\"TIDE_SECRET\")\n            .expect(\n                \"Please provide a TIDE_SECRET value of at \\\n                      least 32 bytes in order to run this example\",\n            )\n            .as_bytes(),\n    ));\n\n    app.with(tide::utils::Before(\n        |mut request: tide::Request\u003c()\u003e| async move {\n            let session = request.session_mut();\n            let visits: usize = session.get(\"visits\").unwrap_or_default();\n            session.insert(\"visits\", visits + 1).unwrap();\n            request\n        },\n    ));\n\n    app.at(\"/\").get(|req: tide::Request\u003c()\u003e| async move {\n        let visits: usize = req.session().get(\"visits\").unwrap();\n        Ok(format!(\"you have visited this website {} times\", visits))\n    });\n\n    app.at(\"/reset\")\n        .get(|mut req: tide::Request\u003c()\u003e| async move {\n            req.session_mut().destroy();\n            Ok(tide::Redirect::new(\"/\"))\n        });\n\n    app.listen(\"127.0.0.1:8080\").await?;\n\n    Ok(())\n}\n```\n\n## Test\n\nThe tests rely on an running instance of mongodb either on your local machine or remote.\nThe quickest way to get an instance up and running locally is using the following docker command:\n\n```\n$ docker run -d -p 27017:27017 -v ~/data:/data/db mongo:4.2\n```\n\nThe tests can then be executed with\n```\n$ cargo test\n```\n\nThe default settings for the mongodb instance is set to 127.0.0.1:27017 but that can be over ridden by setting the HOST and PORT environment variables.\n```\n$ HOST=mymongo.com PORT=1234 cargo test\n```\n\n## Safety\nThis crate uses ``#![deny(unsafe_code)]`` to ensure everything is implemented in\n100% Safe Rust.\n\n## Contributing\nWant to join us? Check out our [\"Contributing\" guide][contributing] and take a\nlook at some of these issues:\n\n- [Issues labeled \"good first issue\"][good-first-issue]\n- [Issues labeled \"help wanted\"][help-wanted]\n\n[contributing]: https://github.com/yoshuawuyts/async-mongodb-session/blob/master.github/CONTRIBUTING.md\n[good-first-issue]: https://github.com/yoshuawuyts/async-mongodb-session/labels/good%20first%20issue\n[help-wanted]: https://github.com/yoshuawuyts/async-mongodb-session/labels/help%20wanted\n\n## License\n\n\u003csup\u003e\nLicensed under either of \u003ca href=\"LICENSE-APACHE\"\u003eApache License, Version\n2.0\u003c/a\u003e or \u003ca href=\"LICENSE-MIT\"\u003eMIT license\u003c/a\u003e at your option.\n\u003c/sup\u003e\n\n\u003cbr/\u003e\n\n\u003csub\u003e\nUnless you explicitly state otherwise, any contribution intentionally submitted\nfor inclusion in this crate by you, as defined in the Apache-2.0 license, shall\nbe dual licensed as above, without any additional terms or conditions.\n\u003c/sub\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhttp-rs%2Fasync-mongodb-session","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhttp-rs%2Fasync-mongodb-session","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhttp-rs%2Fasync-mongodb-session/lists"}