Rust
If your application is written in Rust, it connects to TeselaDB with the official MongoDB driver.
Connect a Rust application to TeselaDB with the official MongoDB driver for Rust. TeselaDB presents itself as a mongos, so the driver works unchanged.
Requirements
- Rust with Cargo.
- The address of one or more nodes, a user with
readWriteon the database and thepki/ca.pemfile of the cluster.
Install the driver
Shell
cargo add mongodb tokio --features tokio/fullStore the connection string
Put the string in an environment variable instead of writing it in the code:
Shell
export TESELADB_URI="mongodb://user:<password>@node-01:27017,node-02:27017/shop?tls=true&tlsCAFile=./ca.pem"Write and read a document
Rust
let client = mongodb::Client::with_uri_str(std::env::var("TESELADB_URI")?).await?;
let orders = client.database("shop").collection::<mongodb::bson::Document>("orders");
orders.insert_one(mongodb::bson::doc! { "total": 149.5 }).await?;
println!("{}", orders.count_documents(mongodb::bson::doc! {}).await?);Check
The program prints the number of documents in orders, which grows by one each time you run it.
Common problems
- The connection closes before authenticating because
tls=trueis missing from the string. - The driver does not trust the node certificate because it does not have the CA of this cluster.