Struct mongodb::sync::ClientSession[][src]

pub struct ClientSession { /* fields omitted */ }
This is supported on crate feature sync only.
Expand description

A MongoDB client session. This struct represents a logical session used for ordering sequential operations. To create a ClientSession, call start_session on a Client.

ClientSession instances are not thread safe or fork safe. They can only be used by one thread or process at a time.

Implementations

The client used to create this session.

The id of this session.

The highest seen cluster time this session has seen so far. This will be None if this session has not been used in an operation yet.

The options used to create this session.

Set the cluster time to the provided one if it is greater than this session’s highest seen cluster time or if this session’s cluster time is None.

Starts a new transaction on this session with the given TransactionOptions. If no options are provided, the session’s defaultTransactionOptions will be used. This session must be passed into each operation within the transaction; otherwise, the operation will be executed outside of the transaction.

session.start_transaction(None)?;
let result = coll.insert_one_with_session(doc! { "x": 1 }, None, &mut session)?;
session.commit_transaction()?;

Commits the transaction that is currently active on this session.

session.start_transaction(None)?;
let result = coll.insert_one_with_session(doc! { "x": 1 }, None, &mut session)?;
session.commit_transaction()?;

This operation will retry once upon failure if the connection and encountered error support retryability. See the documentation here for more information on retryable writes.

Aborts the transaction that is currently active on this session. Any open transaction will be aborted automatically in the Drop implementation of ClientSession.

session.start_transaction(None)?;
match execute_transaction(coll, &mut session) {
    Ok(_) => session.commit_transaction()?,
    Err(_) => session.abort_transaction()?,
}

fn execute_transaction(coll: Collection<Document>, session: &mut ClientSession) -> Result<()> {
    coll.insert_one_with_session(doc! { "x": 1 }, None, session)?;
    coll.delete_one_with_session(doc! { "y": 2 }, None, session)?;
    Ok(())   
}

This operation will retry once upon failure if the connection and encountered error support retryability. See the documentation here for more information on retryable writes.

Trait Implementations

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

Should always be Self

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.