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
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.
Trait Implementations
Auto Trait Implementations
impl<C> RefUnwindSafe for Insert<C> where
C: RefUnwindSafe,
impl<C> UnwindSafe for Insert<C> where
C: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
type Output = T
type Output = T
Should always be Self