Trait green_barrel::models::db_query_api::commons::QCommons
source · [−]pub trait QCommons: Main + Caching + Converters {
Show 15 methods
fn aggregate(
pipeline: Vec<Document>,
options: Option<AggregateOptions>
) -> Result<Vec<Document>, Box<dyn Error>>
where
Self: Serialize + DeserializeOwned + Sized,
{ ... }
fn count_documents(
filter: Option<Document>,
options: Option<CountOptions>
) -> Result<i64, Box<dyn Error>>
where
Self: Serialize + DeserializeOwned + Sized,
{ ... }
fn delete_many(
query: Document,
options: Option<DeleteOptions>
) -> Result<OutputData, Box<dyn Error>>
where
Self: Serialize + DeserializeOwned + Sized,
{ ... }
fn delete_one(
query: Document,
options: Option<DeleteOptions>
) -> Result<OutputData, Box<dyn Error>>
where
Self: Serialize + DeserializeOwned + Sized,
{ ... }
fn distinct(
field_name: &str,
filter: Option<Document>,
options: Option<DistinctOptions>
) -> Result<Vec<Bson>, Box<dyn Error>>
where
Self: Serialize + DeserializeOwned + Sized,
{ ... }
fn drop(
options: Option<DropCollectionOptions>
) -> Result<OutputData, Box<dyn Error>>
where
Self: Serialize + DeserializeOwned + Sized,
{ ... }
fn estimated_document_count(
options: Option<EstimatedDocumentCountOptions>
) -> Result<i64, Box<dyn Error>>
where
Self: Serialize + DeserializeOwned + Sized,
{ ... }
fn find_many_to_doc_list(
filter: Option<Document>,
options: Option<FindOptions>
) -> Result<Option<Vec<Document>>, Box<dyn Error>>
where
Self: Serialize + DeserializeOwned + Sized,
{ ... }
fn find_many_to_json(
filter: Option<Document>,
options: Option<FindOptions>
) -> Result<Option<String>, Box<dyn Error>>
where
Self: Serialize + DeserializeOwned + Sized,
{ ... }
fn find_one_to_doc(
filter: Document,
options: Option<FindOneOptions>
) -> Result<Option<Document>, Box<dyn Error>>
where
Self: Serialize + DeserializeOwned + Sized,
{ ... }
fn find_one_to_json(
filter: Document,
options: Option<FindOneOptions>
) -> Result<String, Box<dyn Error>>
where
Self: Serialize + DeserializeOwned + Sized,
{ ... }
fn find_one_to_instance(
filter: Document,
options: Option<FindOneOptions>
) -> Result<Option<Self>, Box<dyn Error>>
where
Self: Serialize + DeserializeOwned + Sized,
{ ... }
fn find_one_and_delete(
filter: Document,
options: Option<FindOneAndDeleteOptions>
) -> Result<Option<Document>, Box<dyn Error>>
where
Self: Serialize + DeserializeOwned + Sized,
{ ... }
fn collection_name() -> Result<String, Box<dyn Error>>
where
Self: Serialize + DeserializeOwned + Sized,
{ ... }
fn namespace() -> Result<Namespace, Box<dyn Error>>
where
Self: Serialize + DeserializeOwned + Sized,
{ ... }
}
Expand description
Common query methods.
Provided Methods
sourcefn aggregate(
pipeline: Vec<Document>,
options: Option<AggregateOptions>
) -> Result<Vec<Document>, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
fn aggregate(
pipeline: Vec<Document>,
options: Option<AggregateOptions>
) -> Result<Vec<Document>, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
Runs an aggregation operation. https://docs.rs/mongodb/1.2.5/mongodb/struct.Collection.html#method.aggregate See the documentation https://docs.mongodb.com/manual/aggregation/ for more information on aggregations.
Example:
use mongodb::bson::doc;
let pipeline = vec![doc! {}];
let doc_list = ModelName::aggregate(pipeline, None)?;
println!("{:?}", doc_list);
sourcefn count_documents(
filter: Option<Document>,
options: Option<CountOptions>
) -> Result<i64, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
fn count_documents(
filter: Option<Document>,
options: Option<CountOptions>
) -> Result<i64, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
Gets the number of documents matching filter. https://docs.rs/mongodb/1.2.5/mongodb/struct.Collection.html#method.count_documents
Example:
use mongodb::bson::doc;
let filter = doc!{};
let count = ModelName::count_documents(Some(filter), None)?;
println!("{}", count);
sourcefn delete_many(
query: Document,
options: Option<DeleteOptions>
) -> Result<OutputData, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
fn delete_many(
query: Document,
options: Option<DeleteOptions>
) -> Result<OutputData, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
Deletes all documents stored in the collection matching query. https://docs.rs/mongodb/1.2.5/mongodb/struct.Collection.html#method.delete_many
Example:
use mongodb::bson::doc;
let query = doc!{};
let output_data = ModelName::delete_many(query, None)?;
if !output_data.is_valid() {
println!("{}", output_data.err_msg());
}
sourcefn delete_one(
query: Document,
options: Option<DeleteOptions>
) -> Result<OutputData, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
fn delete_one(
query: Document,
options: Option<DeleteOptions>
) -> Result<OutputData, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
Deletes up to one document found matching query. https://docs.rs/mongodb/1.2.5/mongodb/struct.Collection.html#method.delete_one
Example:
use mongodb::bson::doc;
let query = doc!{};
let output_data = ModelName::delete_one(query, None)?;
if !output_data.is_valid() {
println!("{}", output_data.err_msg());
}
sourcefn distinct(
field_name: &str,
filter: Option<Document>,
options: Option<DistinctOptions>
) -> Result<Vec<Bson>, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
fn distinct(
field_name: &str,
filter: Option<Document>,
options: Option<DistinctOptions>
) -> Result<Vec<Bson>, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
Finds the distinct values of the field specified by field_name across the collection. https://docs.rs/mongodb/1.2.5/mongodb/struct.Collection.html#method.distinct
Example:
use mongodb::bson::doc;
let field_name = "";
let filter = doc!{};
let output_data = ModelName::distinct(field_name, Some(filter), None)?;
println!("{:?}", output_data);
sourcefn drop(
options: Option<DropCollectionOptions>
) -> Result<OutputData, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
fn drop(
options: Option<DropCollectionOptions>
) -> Result<OutputData, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
Drops the collection, deleting all data and indexes stored in it. https://docs.rs/mongodb/1.2.5/mongodb/struct.Collection.html#method.drop
Example:
let output_data = ModelName::drop(None)?;
if !output_data.is_valid() {
println!("{}", output_data.err_msg());
}
sourcefn estimated_document_count(
options: Option<EstimatedDocumentCountOptions>
) -> Result<i64, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
fn estimated_document_count(
options: Option<EstimatedDocumentCountOptions>
) -> Result<i64, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
Estimates the number of documents in the collection using collection metadata. https://docs.rs/mongodb/1.2.5/mongodb/struct.Collection.html#method.estimated_document_count
Example:
let count = ModelName::estimated_document_count(None)?;
println!("{}", count);
sourcefn find_many_to_doc_list(
filter: Option<Document>,
options: Option<FindOptions>
) -> Result<Option<Vec<Document>>, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
fn find_many_to_doc_list(
filter: Option<Document>,
options: Option<FindOptions>
) -> Result<Option<Vec<Document>>, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
Finds the documents in the collection matching filter and return document list ( missing fields type ). https://docs.rs/mongodb/1.2.5/mongodb/struct.Collection.html#method.find
Example:
let result = ModelName::find_many_to_doc_list(None, None)?;
if let Some(doc_list) = result {
println!("{:?}", doc_list);
}
sourcefn find_many_to_json(
filter: Option<Document>,
options: Option<FindOptions>
) -> Result<Option<String>, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
fn find_many_to_json(
filter: Option<Document>,
options: Option<FindOptions>
) -> Result<Option<String>, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
Finds the documents in the collection matching filter and return in JSON format ( missing fields type ). https://docs.rs/mongodb/1.2.5/mongodb/struct.Collection.html#method.find
Example:
let result = ModelName::find_many_to_json(None, None)?;
if let Some(json_line) = result {
println!("{}", json_line);
}
sourcefn find_one_to_doc(
filter: Document,
options: Option<FindOneOptions>
) -> Result<Option<Document>, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
fn find_one_to_doc(
filter: Document,
options: Option<FindOneOptions>
) -> Result<Option<Document>, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
Finds a single document in the collection matching filter and return in Doc format ( missing fields type ). https://docs.rs/mongodb/1.2.5/mongodb/struct.Collection.html#method.find_one
Example:
use mongodb::bson::doc;
let filter = doc!{"username": "user_1"};
let result = ModelName::find_one_to_doc(filter, None)?;
if let Some(doc) = result {
println!("{:?}", doc);
}
sourcefn find_one_to_json(
filter: Document,
options: Option<FindOneOptions>
) -> Result<String, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
fn find_one_to_json(
filter: Document,
options: Option<FindOneOptions>
) -> Result<String, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
Finds a single document in the collection matching filter and return in JSON format. https://docs.rs/mongodb/1.2.5/mongodb/struct.Collection.html#method.find_one
Example:
use mongodb::bson::doc;
let filter = doc!{"username": "user_1"};
let json = ModelName::find_one_to_json(filter, None)?;
println!("{}", json);
sourcefn find_one_to_instance(
filter: Document,
options: Option<FindOneOptions>
) -> Result<Option<Self>, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
fn find_one_to_instance(
filter: Document,
options: Option<FindOneOptions>
) -> Result<Option<Self>, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
Finds a single document in the collection matching filter and return as model instance. https://docs.rs/mongodb/1.2.5/mongodb/struct.Collection.html#method.find_one
Example:
use mongodb::bson::doc;
let filter = doc!{"username": "user_1"};
let result = ModelName::find_one_to_instance(filter, None)?;
if let Some(instance) = result {
println!("{:?}", instance);
}
sourcefn find_one_and_delete(
filter: Document,
options: Option<FindOneAndDeleteOptions>
) -> Result<Option<Document>, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
fn find_one_and_delete(
filter: Document,
options: Option<FindOneAndDeleteOptions>
) -> Result<Option<Document>, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
Atomically finds up to one document in the collection matching filter and deletes it ( missing fields type ). Returns the deleted document (in Doc format). https://docs.rs/mongodb/1.2.5/mongodb/struct.Collection.html#method.find_one_and_delete
Example:
use mongodb::bson::doc; let filter = doc!{“username”: “user_1”}; let result = ModelName::find_one_and_delete(filter, None)?; if let Some(doc) = result) { println!(“{:?}”, doc); }
sourcefn collection_name() -> Result<String, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
fn collection_name() -> Result<String, Box<dyn Error>>where
Self: Serialize + DeserializeOwned + Sized,
Gets the name of the Collection. https://docs.rs/mongodb/1.1.1/mongodb/struct.Collection.html#method.name
Example:
let name = ModelName::name()?;
println!("{}", name);