diff --git a/axumtest/src/cases/mod.rs b/axumtest/src/cases/mod.rs index 0a32386..08a2b12 100644 --- a/axumtest/src/cases/mod.rs +++ b/axumtest/src/cases/mod.rs @@ -7,7 +7,10 @@ use axum::middleware; use axum::routing::get; use axum::Router; use futures::stream::TryStreamExt; +use futures::StreamExt; +use mongodb::bson::doc; use mongodb::bson::Document; +use mongodb::options::FindOptions; use crate::auth; use crate::State; @@ -32,9 +35,20 @@ pub fn router(state: Arc, ci_usr: String, ci_pwd: String, ci_role: String async fn all_cases_on_collection(Path(collection): Path, state: Arc) -> String { let collection = state.db.collection::(&collection); - let mut cursor = collection.find(None, None).await.unwrap(); - while let Some(record) = cursor.try_next().await.unwrap() { - tracing::debug!("{:?}", record.get_str("caseID")); - } + let options = FindOptions::builder() + .projection(doc! { "caseID": 1 }) + .build(); + let cursor = collection.find(None, options).await.unwrap(); + + let result = cursor + .map(|r| r.unwrap().get_str("caseID").unwrap().to_lowercase()) + .collect::>() + .await; + // while let Some(record) = cursor.try_next().await.unwrap() { + // tracing::debug!("{:?}", record.get_str("caseID").unwrap()); + // } + + tracing::debug!("Cases: {:?}", result); + format!("Cases!") }