-1

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

  1. error[E0432]: unresolved import mongodb::options

  2. use mongodb::{Client, options::ClientOptions}; | ^^^^^^^ could not find options in mongodb

  3. let client = Client::with_options(client_options)?; | ^^^^^^^^^^^^ function or associated item not found in std::sync::Arc<r2d2_mongodb::mongodb::ClientInner>

enter image description here

Niraj Gawande
  • 137
  • 1
  • 11

1 Answers1

0

I put start in the version number in Cargo.toml. Changing it to latest version number solved issue.

Niraj Gawande
  • 137
  • 1
  • 11