{"id":13439013,"url":"https://github.com/mongodb-labs/mongo-rust-driver-prototype","last_synced_at":"2025-03-20T06:32:06.704Z","repository":{"id":8703914,"uuid":"10370054","full_name":"mongodb-labs/mongo-rust-driver-prototype","owner":"mongodb-labs","description":"This is superseded by the official MongoDB Rust Driver","archived":true,"fork":false,"pushed_at":"2019-12-19T15:17:46.000Z","size":1937,"stargazers_count":376,"open_issues_count":0,"forks_count":72,"subscribers_count":29,"default_branch":"master","last_synced_at":"2024-12-18T19:03:40.941Z","etag":null,"topics":["mongodb-driver","rust"],"latest_commit_sha":null,"homepage":"https://github.com/mongodb/mongo-rust-driver","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/mongodb-labs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-05-29T21:42:45.000Z","updated_at":"2024-11-28T16:27:16.000Z","dependencies_parsed_at":"2022-07-09T20:46:16.250Z","dependency_job_id":null,"html_url":"https://github.com/mongodb-labs/mongo-rust-driver-prototype","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-labs%2Fmongo-rust-driver-prototype","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-labs%2Fmongo-rust-driver-prototype/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-labs%2Fmongo-rust-driver-prototype/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mongodb-labs%2Fmongo-rust-driver-prototype/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mongodb-labs","download_url":"https://codeload.github.com/mongodb-labs/mongo-rust-driver-prototype/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244565977,"owners_count":20473399,"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":["mongodb-driver","rust"],"created_at":"2024-07-31T03:01:10.440Z","updated_at":"2025-03-20T06:32:01.691Z","avatar_url":"https://github.com/mongodb-labs.png","language":"Rust","funding_links":[],"categories":["Libraries","库","库 Libraries"],"sub_categories":["Database","数据库","数据库 Database","Rust"],"readme":"# This Repository is NOT a supported MongoDB product\n\n\n[![Travis](https://travis-ci.org/mongodb-labs/mongo-rust-driver-prototype.svg)](https://travis-ci.org/mongodb-labs/mongo-rust-driver-prototype) [![Crates.io](https://img.shields.io/crates/v/mongodb.svg)](https://crates.io/crates/mongodb) [![docs.rs](https://docs.rs/mongodb/badge.svg)](https://docs.rs/mongodb) [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)\n\nMongoDB Rust Driver Prototype\n=============================\n\n**NOTE**: This driver is superseded by the [official MongoDB Rust driver](https://github.com/mongodb/mongo-rust-driver), and will no longer be updated.\n\nThis branch contains active development on a new driver written for Rust 1.x and MongoDB 3.0.x.\n\nThe API and implementation are currently subject to change at any time. You should not use this driver in production as it is still under development and is in no way supported by MongoDB Inc. We absolutely encourage you to experiment with it and provide us feedback on the API, design, and implementation. Bug reports and suggestions for improvements are welcomed, as are pull requests.\n\n**Note**: This driver currently only supports MongoDB 3.0.x and 3.2.x. This driver is **not** expected to work with MongoDB 2.6 or any earlier versions. Do not use this driver if you need support for other versions of MongoDB.\n\nInstallation\n------------\n\n#### Dependencies\n\n-\t[Rust 1.7+ with Cargo](http://rust-lang.org)\n\n#### Importing\n\nThe driver is available on crates.io. To use the MongoDB driver in your code, add the bson and mongodb packages to your `Cargo.toml`:\n\n```toml\n[dependencies]\nmongodb = \"0.3.11\"\n```\n\nAlternately, you can use the MongoDB driver with SSL support. To do this, you must have OpenSSL installed on your system. Then, enable the `ssl` feature for MongoDB in your Cargo.toml:\n\n```toml\n[dependencies]\n# ...\nmongodb = { version = \"0.3.11\", features = [\"ssl\"] }\n```\n\nThen, import the bson and driver libraries within your code.\n\n```rust\n#[macro_use(bson, doc)]\nextern crate mongodb;\n```\n\nor with Rust 2018:\n\n```rust\nextern crate mongodb;\nuse mongodb::{bson, doc};\n```\n\nExamples\n--------\n\nHere's a basic example of driver usage:\n\n```rust\nuse mongodb::{Bson, bson, doc};\nuse mongodb::{Client, ThreadedClient};\nuse mongodb::db::ThreadedDatabase;\n\nfn main() {\n    let client = Client::connect(\"localhost\", 27017)\n        .expect(\"Failed to initialize standalone client.\");\n\n    let coll = client.db(\"test\").collection(\"movies\");\n\n    let doc = doc! {\n        \"title\": \"Jaws\",\n        \"array\": [ 1, 2, 3 ],\n    };\n\n    // Insert document into 'test.movies' collection\n    coll.insert_one(doc.clone(), None)\n        .ok().expect(\"Failed to insert document.\");\n\n    // Find the document and receive a cursor\n    let mut cursor = coll.find(Some(doc.clone()), None)\n        .ok().expect(\"Failed to execute find.\");\n\n    let item = cursor.next();\n\n    // cursor.next() returns an Option\u003cResult\u003cDocument\u003e\u003e\n    match item {\n        Some(Ok(doc)) =\u003e match doc.get(\"title\") {\n            Some(\u0026Bson::String(ref title)) =\u003e println!(\"{}\", title),\n            _ =\u003e panic!(\"Expected title to be a string!\"),\n        },\n        Some(Err(_)) =\u003e panic!(\"Failed to get next from server!\"),\n        None =\u003e panic!(\"Server returned no results!\"),\n    }\n}\n```\n\nTo connect with SSL, use either `ClientOptions::with_ssl` or `ClientOptions::with_unauthenticated_ssl` and then `Client::connect_with_options`. Afterwards, the client can be used as above (note that the server will have to be configured to accept SSL connections and that you'll have to generate your own keys and certificates):\n\n```rust\nuse mongodb::{Bson, bson, doc};\nuse mongodb::{Client, ClientOptions, ThreadedClient};\nuse mongodb::db::ThreadedDatabase;\n\nfn main() {\n    // Path to file containing trusted server certificates.\n    let ca_file = \"path/to/ca.crt\";\n    // Path to file containing client certificate.\n    let certificate = \"path/to/client.crt\";\n    // Path to file containing the client private key.\n    let key_file = \"path/to/client.key\";\n    // Whether or not to verify that the server certificate is valid. Unless you're just testing out something locally, this should ALWAYS be true.\n    let verify_peer = true;\n\n    let options = ClientOptions::with_ssl(ca_file, certificate, key_file, verify_peer);\n\n    let client = Client::connect_with_options(\"localhost\", 27017, options)\n        .expect(\"Failed to initialize standalone client.\");\n\n    let coll = client.db(\"test\").collection(\"movies\");\n\n    let doc = doc! {\n        \"title\": \"Jaws\",\n        \"array\": [ 1, 2, 3 ],\n    };\n\n    // Insert document into 'test.movies' collection\n    coll.insert_one(doc.clone(), None)\n        .ok().expect(\"Failed to insert document.\");\n\n    ...\n}\n```\n\nTesting\n-------\n\nThe driver test suite is largely composed of integration tests and behavioral unit-tests, relying on the official [MongoDB specifications repo](https://github.com/mongodb/specifications). \n\nThe easiest way to thoroughly test the driver is to set your fork up with TravisCI. However, if you'd rather test the driver locally, you'll need to setup integration and specification tests.\n\n\u003e NOTE: Each integration test uses a unique database/collection to allow tests to be parallelized, and will drop their dependencies before running. However, effects are _not_ cleaned up afterwards.\n\n#### Setting up integration tests\n\nAll integration tests run on the default MongoDB port, 27017. Before running the tests, ensure that a test database is setup to listen on that port.\n\nIf you don't have mongodb installed, download and install a version from [the MongoDB Download Center](https://www.mongodb.com/download-center). You can see a full list of versions being tested on Travis in [the travis config](/.travis.yml).\n\nAfter installation, run a MongoDB server on 27017:\n\n```\nmkdir -p ./data/test_db\nmongod --dbpath ./data/test_db\n```\n\n#### Setting up the specifications submodule\n\nPull in the specifications submodule at `tests/json/data/specs`.\n\n```\ngit submodule update --init\n```\n\n#### Running Tests\n\nRun tests like a regular Rust program:\n\n```\ncargo test --verbose\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmongodb-labs%2Fmongo-rust-driver-prototype","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmongodb-labs%2Fmongo-rust-driver-prototype","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmongodb-labs%2Fmongo-rust-driver-prototype/lists"}