pub async fn query(
auth: &impl FirebaseAuthBearer,
collection_id: &str,
value: Value,
operator: FieldOperator,
field: &str,
) -> Result<Query>
Expand description
Queries the database for specific documents, for example all documents in a collection of ‘type’ == “car”.
Example:
#[derive(Debug, Serialize, Deserialize)]
struct DemoDTO { a_string: String, an_int: u32, }
use firestore_db_and_auth::{documents, dto};
let values: documents::Query = documents::query(&session, "tests", "Sam Weiss".into(), dto::FieldOperator::EQUAL, "id").await.unwrap();
for metadata in values {
println!("id: {}, created: {}, updated: {}", &metadata.name, metadata.create_time.as_ref().unwrap(), metadata.update_time.as_ref().unwrap());
// Fetch the actual document
// The data is wrapped in a Result<> because fetching new data could have failed
let doc : DemoDTO = documents::read_by_name(&session, &metadata.name).await.unwrap();
println!("{:?}", doc);
}
§Arguments
- ‘auth’ The authentication token
- ‘collectionid’ The collection id; “my_collection” or “a/nested/collection”
- ‘value’ The query / filter value. For example “car”.
- ‘operator’ The query operator. For example “EQUAL”.
- ‘field’ The query / filter field. For example “type”.