我正在尝试使用 mongodb 库在 rust 中连接到 mongodb
这是代码
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
}
我收到以下错误
错误[E0432]:未解决的导入
mongodb::options
使用 mongodb::{Client, options::ClientOptions}; |
options
^^^^^^^找不到mongodb
让客户端 = Client::with_options(client_options)?; | ^^^^^^^^^^^^ 函数或相关项目未在
std::sync::Arc<r2d2_mongodb::mongodb::ClientInner>