Struct mongod::query::Insert[][src]

pub struct Insert<C: Collection> { /* fields omitted */ }
Expand description

A querier to insert documents into a MongoDB collection.

Examples

Insert a document into a collection.

use serde::{Deserialize, Serialize};

#[derive(Bson, Mongo, Deserialize, Serialize)]
#[mongo(collection="users", field, filter, update)]
pub struct User {
    name: String,
}

let client = mongod::Client::new();

let user = User { name: "foo".to_owned() };

let result = mongod::query::Insert::<User>::new()
    .query(&client, vec![user])
    .await
    .unwrap();

println!("(index: oid) {:?}", result);

Implementations

Constructs a Insert querier.

Opt out of document-level validation.

If true, when an insert fails, return without performing the remaining writes. If false, when a write fails, continue with the remaining writes, if any.

Defaults to true.

The write concern for the operation.

Query the database with this querier.

Errors

This method fails if:

  • any of the documents could not be converted into a BSON Document.
  • the mongodb encountered an error.

Query the database with this querier in a blocking context.

Optional

This requires the optional blocking feature to be enabled.

Errors

This method fails if:

  • any of the documents could not be converted into a BSON Document.
  • the mongodb encountered an error.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Returns the “default value” for a type. Read more

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.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

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.