Function get_champions_with_no_role

Source
async fn get_champions_with_no_role(
    collection: &Collection<ChampionData>,
) -> Result<Vec<ChampionData>>
Expand description

⚙️ Retrieves all champions from the database without filtering by role.

This asynchronous function queries a MongoDB collection to retrieve all ChampionData documents, regardless of their role. It is used to obtain a complete list of champions stored in the collection.

§Parameters:

  • collection: A reference to a MongoDB collection of ChampionData representing the champion data stored in the database.

§Returns:

  • Result<Vec<ChampionData>, mongodb::error::Error>: On success, returns a vector of all ChampionData objects in the collection. On failure, returns an Error from MongoDB detailing the issue.

§Example:

let champions = get_champions_with_no_role(&collection).await?;
for champion in champions {
    println!("Champion: {}", champion.name);
}

§⚠️ Notes:

  • The function uses an empty filter ({}) to retrieve all documents in the ChampionData collection.
  • The result is collected into a vector using the try_collect method, which allows for asynchronous processing of the cursor results.
  • get_champions_by_role: Retrieves champions filtered by a specific role from the collection.

§Dependencies:

  • This function depends on a MongoDB collection that stores ChampionData documents.
  • Requires the futures crate for the try_collect method to handle the cursor results asynchronously.