pub struct Collection { /* private fields */ }Expand description
A collection of documents in the database.
Collections are analogous to tables in relational databases and store JSON documents. They provide methods for inserting, querying, updating, and deleting documents.
§Example
use luckdb::{Client, Document};
use serde_json::json;
let mut client = Client::new("mongodb://localhost");
let db = client.db("mydb");
let coll = db.collection("users");
// Insert a document
let user = json!({"name": "Alice", "email": "alice@example.com"});
coll.insert(user).unwrap();Implementations§
Source§impl Collection
impl Collection
Sourcepub fn new(name: String) -> Self
pub fn new(name: String) -> Self
Creates a new empty collection with the given name.
§Arguments
name- The name of the new collection.
Sourcepub fn find(
&self,
query: Query,
options: Option<FindOptions>,
) -> Result<Vec<(DocId, Document)>>
pub fn find( &self, query: Query, options: Option<FindOptions>, ) -> Result<Vec<(DocId, Document)>>
Sourcepub fn find_one(
&self,
query: Query,
options: Option<FindOptions>,
) -> Result<(DocId, Document)>
pub fn find_one( &self, query: Query, options: Option<FindOptions>, ) -> Result<(DocId, Document)>
Sourcepub fn find_one_and_update(
&mut self,
query: Query,
update: UpdateDocument,
options: Option<FindOneAndUpdateOptions>,
) -> Result<Option<(DocId, Document)>>
pub fn find_one_and_update( &mut self, query: Query, update: UpdateDocument, options: Option<FindOneAndUpdateOptions>, ) -> Result<Option<(DocId, Document)>>
Finds a document, updates it, and returns the document (either before or after the update).
§Arguments
query- The query to filter documents.update- The update operations to apply.options- Optional parameters including upsert behavior and which document version to return.
§Returns
The document before or after the update, depending on options.
pub fn find_one_and_replace( &mut self, query: Query, replacement: Document, options: Option<FindOneAndReplaceOptions>, ) -> Result<Option<(DocId, Document)>>
pub fn find_one_and_delete( &mut self, query: Query, options: Option<FindOneAndDeleteOptions>, ) -> Result<Option<(DocId, Document)>>
Sourcepub fn update_one(
&mut self,
query: Query,
update: UpdateDocument,
upsert: bool,
) -> Result<usize>
pub fn update_one( &mut self, query: Query, update: UpdateDocument, upsert: bool, ) -> Result<usize>
Sourcepub fn update_many(
&mut self,
query: Query,
update: UpdateDocument,
) -> Result<usize>
pub fn update_many( &mut self, query: Query, update: UpdateDocument, ) -> Result<usize>
pub fn replace_one( &mut self, query: Query, replacement: Document, upsert: bool, ) -> Result<usize>
Sourcepub fn delete_one(&mut self, query: Query) -> Result<usize>
pub fn delete_one(&mut self, query: Query) -> Result<usize>
Sourcepub fn delete_many(&mut self, query: Query) -> Result<usize>
pub fn delete_many(&mut self, query: Query) -> Result<usize>
Sourcepub fn count_documents(&self, query: Query) -> Result<usize>
pub fn count_documents(&self, query: Query) -> Result<usize>
Sourcepub fn estimated_document_count(&self) -> Result<usize>
pub fn estimated_document_count(&self) -> Result<usize>
Returns the estimated count of documents in the collection.
§Returns
The total number of documents in the collection.
Sourcepub fn create_index(&mut self, index: Index) -> Result<()>
pub fn create_index(&mut self, index: Index) -> Result<()>
Sourcepub fn drop_index(&mut self, name: &str) -> Result<()>
pub fn drop_index(&mut self, name: &str) -> Result<()>
Sourcepub fn list_indexes(&self) -> Result<Vec<Index>>
pub fn list_indexes(&self) -> Result<Vec<Index>>
Sourcepub fn drop_indexes(&mut self) -> Result<()>
pub fn drop_indexes(&mut self) -> Result<()>
Drops all indexes from the collection.
pub fn stats(&self) -> Result<CollectionStats>
pub fn aggregate( &self, pipeline: Vec<AggregationStage>, ) -> Result<Vec<Document>>
pub fn distinct(&self, field: &str, query: Option<Query>) -> Result<Vec<Value>>
pub fn count(&self) -> usize
Source§impl Collection
impl Collection
pub fn bulk_write( &mut self, operations: Vec<BulkWriteOperation>, options: Option<BulkWriteOptions>, ) -> Result<BulkWriteResult>
Trait Implementations§
Source§impl Clone for Collection
impl Clone for Collection
Source§fn clone(&self) -> Collection
fn clone(&self) -> Collection
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for Collection
impl Debug for Collection
Source§impl<'de> Deserialize<'de> for Collection
impl<'de> Deserialize<'de> for Collection
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl From<Collection> for PersistentCollection
impl From<Collection> for PersistentCollection
Source§fn from(collection: Collection) -> Self
fn from(collection: Collection) -> Self
Converts to this type from the input type.
Source§impl From<PersistentCollection> for Collection
impl From<PersistentCollection> for Collection
Source§fn from(persistent: PersistentCollection) -> Self
fn from(persistent: PersistentCollection) -> Self
Converts to this type from the input type.
Auto Trait Implementations§
impl Freeze for Collection
impl RefUnwindSafe for Collection
impl Send for Collection
impl Sync for Collection
impl Unpin for Collection
impl UnwindSafe for Collection
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more