I am trying to connect to mongodb using in rust using mongodb library
here is the code
use actix_web::{App, HttpServer};
use mongodb::{Client, options::ClientOptions};
#[actix_rt::main]
async fn main() -> std::io::Result<()> {
// Parse a connection string into an options struct.
let mut client_options = ClientOptions::parse("mongodb://localhost:27017")?;
client_options.app_name = Some("My App".to_string());
let client = Client::with_options(client_options)?;
for db_name in client.list_database_names(None)? {
println!("{}", db_name);
}
HttpServer::new(move || {
App::new()
})
.bind("127.0.0.1:3000")?
.run()
.await
}
I am getting following errors
error[E0432]: unresolved import
mongodb::options
use mongodb::{Client, options::ClientOptions}; | ^^^^^^^ could not find
options
inmongodb
let client = Client::with_options(client_options)?; | ^^^^^^^^^^^^ function or associated item not found in
std::sync::Arc<r2d2_mongodb::mongodb::ClientInner>