thedodd / wither

An ODM for MongoDB built on the official MongoDB Rust driver.
https://docs.rs/wither
Other
324 stars 40 forks source link

How to use the Model::Find to complete a find_all function #66

Closed surfingtomchen closed 3 years ago

surfingtomchen commented 3 years ago

Hello,

I try to use Model::Find to complete a find_all function, but when I get the ModelCursor as result, I don't know how to iterate it. I can neither use the example code by calling next() nor use the example of Mongo official as cursor is a private member of ModelCursor.

  1. Wither Example which is not working ( next() method not found in wither::ModelCursor<models::role::Role>)
let mut cursor = User::find(mongodb, None, None).await?;
let mut v: Vec<User> = vec![];

while let Some(user) = cursor.next().await {
    v.push(user);
}
  1. MongoDB official example which is also not working ( cursor is a private member of ModelCursor)
    
    let cursor = coll.find(Some(doc! { "x": 1 }), None).await?;

let results: Vec<Result> = cursor.collect().await;



It will be appreciated if there is any examples, thanks.
surfingtomchen commented 3 years ago

Solved as I need to add

use futures::stream::StreamExt;

thedodd commented 3 years ago

🍾