From e3b91e5c2f07605b9b5b19e5bb79e996ad29ee2d Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Fri, 19 Aug 2022 17:10:12 -0300 Subject: [PATCH] Capture the cases names The idea is to, later, retrieve each case on separate tasks, 'cause getting all of them in a single request is sloooooooooooow. --- axumtest/src/cases/mod.rs | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) 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!") }