Docs for bulk operation

pull/13/head
Thijs Cadier 9 years ago
parent 0c4428611b
commit 02c62c1f9b

@ -7,13 +7,21 @@ use super::collection::Collection;
use super::Result; use super::Result;
/// `BulkOperation` provides an abstraction for submitting multiple write operations as a single batch.
///
/// Create a `BulkOperation` by calling `create_bulk_operation` on a `Collection`. After adding all of
/// the write operations using the functions on this struct, `execute` to execute the operation on
/// the server. After executing the bulk operation is consumed and cannot be used anymore.
pub struct BulkOperation<'a> { pub struct BulkOperation<'a> {
_collection: &'a Collection<'a>, _collection: &'a Collection<'a>,
inner: *mut bindings::mongoc_bulk_operation_t inner: *mut bindings::mongoc_bulk_operation_t
} }
impl<'a>BulkOperation<'a> { impl<'a>BulkOperation<'a> {
pub fn new( /// Create a new bulk operation, only for internal usage.
#[doc(hidden)]
pub unsafe fn new(
collection: &'a Collection<'a>, collection: &'a Collection<'a>,
inner: *mut bindings::mongoc_bulk_operation_t inner: *mut bindings::mongoc_bulk_operation_t
) -> BulkOperation<'a> { ) -> BulkOperation<'a> {
@ -26,8 +34,6 @@ impl<'a> BulkOperation<'a> {
/// Queue an insert of a single document into a bulk operation. /// Queue an insert of a single document into a bulk operation.
/// The insert is not performed until `execute` is called. /// The insert is not performed until `execute` is called.
///
/// See: http://api.mongodb.org/c/current/mongoc_bulk_operation_insert.html
pub fn insert( pub fn insert(
&self, &self,
document: &Document document: &Document
@ -42,10 +48,8 @@ impl<'a> BulkOperation<'a> {
Ok(()) Ok(())
} }
/// Queue removal of al documents matching selector into a bulk operation. /// Queue removal of all documents matching the provided selector into a bulk operation.
/// The removal is not performed until `execute` is called. /// The removal is not performed until `execute` is called.
///
/// See: http://api.mongodb.org/c/current/mongoc_bulk_operation_remove.html
pub fn remove( pub fn remove(
&self, &self,
selector: &Document selector: &Document
@ -62,8 +66,6 @@ impl<'a> BulkOperation<'a> {
/// Queue removal of a single document into a bulk operation. /// Queue removal of a single document into a bulk operation.
/// The removal is not performed until `execute` is called. /// The removal is not performed until `execute` is called.
///
/// See: http://api.mongodb.org/c/current/mongoc_bulk_operation_remove_one.html
pub fn remove_one( pub fn remove_one(
&self, &self,
selector: &Document selector: &Document
@ -80,8 +82,6 @@ impl<'a> BulkOperation<'a> {
/// Queue replacement of a single document into a bulk operation. /// Queue replacement of a single document into a bulk operation.
/// The replacement is not performed until `execute` is called. /// The replacement is not performed until `execute` is called.
///
/// See: http://api.mongodb.org/c/current/mongoc_bulk_operation_remove_one.html
pub fn replace_one( pub fn replace_one(
&self, &self,
selector: &Document, selector: &Document,
@ -105,8 +105,6 @@ impl<'a> BulkOperation<'a> {
/// ///
/// TODO: document must only contain fields whose key starts /// TODO: document must only contain fields whose key starts
/// with $, these is no error handling for this. /// with $, these is no error handling for this.
///
/// See: http://api.mongodb.org/c/current/mongoc_bulk_operation_update_one.html
pub fn update_one( pub fn update_one(
&self, &self,
selector: &Document, selector: &Document,
@ -130,8 +128,6 @@ impl<'a> BulkOperation<'a> {
/// ///
/// TODO: document must only contain fields whose key starts /// TODO: document must only contain fields whose key starts
/// with $, these is no error handling for this. /// with $, these is no error handling for this.
///
/// See: http://api.mongodb.org/c/current/mongoc_bulk_operation_update_one.html
pub fn update( pub fn update(
&self, &self,
selector: &Document, selector: &Document,
@ -157,8 +153,6 @@ impl<'a> BulkOperation<'a> {
/// multiple times. /// multiple times.
/// ///
/// Returns a document with an overview of the bulk operation if successfull. /// Returns a document with an overview of the bulk operation if successfull.
///
/// See: http://api.mongodb.org/c/current/mongoc_bulk_operation_execute.html
pub fn execute(self) -> Result<Document> { pub fn execute(self) -> Result<Document> {
// Bsonc to store the reply // Bsonc to store the reply
let mut reply = Bsonc::new(); let mut reply = Bsonc::new();

@ -307,7 +307,7 @@ impl<'a> Collection<'a> {
) )
}; };
BulkOperation::new(self, inner) unsafe { BulkOperation::new(self, inner) }
} }
pub fn drop(&mut self) -> Result<()> { pub fn drop(&mut self) -> Result<()> {

Loading…
Cancel
Save