< 返回版块

suntopo 发表于 2020-05-25 11:09

#[get("/hello")]
pub fn hello(conn: MongoDbConn) -> Json<Vec<Test>> {
    let cursor = conn.collection("test").find(None, None).unwrap();
    let mut tests: Vec<Test> = Vec::new();
    for result in cursor {
        if let Ok(item) = result {
            let test = bson::from_bson(Document::from(item)); // 1. 提示错误
            tests.push(test);
        }
    }

    Json(tests)
}

报错如下:

error[E0308]: mismatched types
  --> src/models/user.rs:49:40
   |
49 |             let test = bson::from_bson(Document::from(item));
   |                                        ^^^^^^^^^^^^^^^^^^^^
   |                                        |
   |                                        expected enum `rocket_contrib::databases::mongodb::Bson`, found struct `rocket_contrib::databases::mongodb::ordered::OrderedDocument`
   |                                        help: try using a variant of the expected enum: `rocket_contrib::databases::mongodb::Bson::Document(Document::from(item))`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
error: could not compile `zoomeye`.

在这里卡了一天了,不知道怎么解决。

评论区

写评论
作者 suntopo 2020-05-25 12:54

对以下内容的回复:

的确是可以了

Cupnfish 2020-05-25 11:41

help: try using a variant of the expected enum: rocket_contrib::databases::mongodb::Bson::Document(Document::from(item)) 这里不是说清楚了么。。。你按照这个试试啊

1 共 2 条评论, 1 页