pub struct Document { /* private fields */ }
Expand description
A BSON document represented as an associative HashMap with insertion ordering.
Implementations§
Source§impl Document
impl Document
Sourcepub fn iter(&self) -> DocumentIterator<'_>
pub fn iter(&self) -> DocumentIterator<'_>
Gets an iterator over the entries of the map.
Sourcepub fn get(&self, key: &str) -> Option<&Bson>
pub fn get(&self, key: &str) -> Option<&Bson>
Returns a reference to the Bson corresponding to the key.
Sourcepub fn get_mut(&mut self, key: &str) -> Option<&mut Bson>
pub fn get_mut(&mut self, key: &str) -> Option<&mut Bson>
Gets a mutable reference to the Bson corresponding to the key
Sourcepub fn get_f64(&self, key: &str) -> Result<f64, ValueAccessError>
pub fn get_f64(&self, key: &str) -> Result<f64, ValueAccessError>
Get a floating point value for this key if it exists and has the correct type.
Sourcepub fn get_f64_mut(&mut self, key: &str) -> Result<&mut f64, ValueAccessError>
pub fn get_f64_mut(&mut self, key: &str) -> Result<&mut f64, ValueAccessError>
Get a mutable reference to a floating point value for this key if it exists and has the correct type.
Sourcepub fn get_str(&self, key: &str) -> Result<&str, ValueAccessError>
pub fn get_str(&self, key: &str) -> Result<&str, ValueAccessError>
Get a string slice this key if it exists and has the correct type.
Sourcepub fn get_str_mut(&mut self, key: &str) -> Result<&mut str, ValueAccessError>
pub fn get_str_mut(&mut self, key: &str) -> Result<&mut str, ValueAccessError>
Get a mutable string slice this key if it exists and has the correct type.
Sourcepub fn get_array(&self, key: &str) -> Result<&Vec<Bson>, ValueAccessError>
pub fn get_array(&self, key: &str) -> Result<&Vec<Bson>, ValueAccessError>
Get a reference to an array for this key if it exists and has the correct type.
Sourcepub fn get_array_mut(
&mut self,
key: &str,
) -> Result<&mut Vec<Bson>, ValueAccessError>
pub fn get_array_mut( &mut self, key: &str, ) -> Result<&mut Vec<Bson>, ValueAccessError>
Get a mutable reference to an array for this key if it exists and has the correct type.
Sourcepub fn get_document(&self, key: &str) -> Result<&Document, ValueAccessError>
pub fn get_document(&self, key: &str) -> Result<&Document, ValueAccessError>
Get a reference to a document for this key if it exists and has the correct type.
Sourcepub fn get_document_mut(
&mut self,
key: &str,
) -> Result<&mut Document, ValueAccessError>
pub fn get_document_mut( &mut self, key: &str, ) -> Result<&mut Document, ValueAccessError>
Get a mutable reference to a document for this key if it exists and has the correct type.
Sourcepub fn get_bool(&self, key: &str) -> Result<bool, ValueAccessError>
pub fn get_bool(&self, key: &str) -> Result<bool, ValueAccessError>
Get a bool value for this key if it exists and has the correct type.
Sourcepub fn get_bool_mut(&mut self, key: &str) -> Result<&mut bool, ValueAccessError>
pub fn get_bool_mut(&mut self, key: &str) -> Result<&mut bool, ValueAccessError>
Get a mutable reference to a bool value for this key if it exists and has the correct type.
Sourcepub fn get_i32(&self, key: &str) -> Result<i32, ValueAccessError>
pub fn get_i32(&self, key: &str) -> Result<i32, ValueAccessError>
Get an i32 value for this key if it exists and has the correct type.
Sourcepub fn get_i32_mut(&mut self, key: &str) -> Result<&mut i32, ValueAccessError>
pub fn get_i32_mut(&mut self, key: &str) -> Result<&mut i32, ValueAccessError>
Get a mutable reference to an i32 value for this key if it exists and has the correct type.
Sourcepub fn get_i64(&self, key: &str) -> Result<i64, ValueAccessError>
pub fn get_i64(&self, key: &str) -> Result<i64, ValueAccessError>
Get an i64 value for this key if it exists and has the correct type.
Sourcepub fn get_i64_mut(&mut self, key: &str) -> Result<&mut i64, ValueAccessError>
pub fn get_i64_mut(&mut self, key: &str) -> Result<&mut i64, ValueAccessError>
Get a mutable reference to an i64 value for this key if it exists and has the correct type.
Sourcepub fn get_timestamp(&self, key: &str) -> Result<Timestamp, ValueAccessError>
pub fn get_timestamp(&self, key: &str) -> Result<Timestamp, ValueAccessError>
Get a time stamp value for this key if it exists and has the correct type.
Sourcepub fn get_timestamp_mut(
&mut self,
key: &str,
) -> Result<&mut Timestamp, ValueAccessError>
pub fn get_timestamp_mut( &mut self, key: &str, ) -> Result<&mut Timestamp, ValueAccessError>
Get a mutable reference to a time stamp value for this key if it exists and has the correct type.
Sourcepub fn get_binary_generic(
&self,
key: &str,
) -> Result<&Vec<u8>, ValueAccessError>
pub fn get_binary_generic( &self, key: &str, ) -> Result<&Vec<u8>, ValueAccessError>
Get a reference to a generic binary value for this key if it exists and has the correct type.
Sourcepub fn get_binary_generic_mut(
&mut self,
key: &str,
) -> Result<&mut Vec<u8>, ValueAccessError>
pub fn get_binary_generic_mut( &mut self, key: &str, ) -> Result<&mut Vec<u8>, ValueAccessError>
Get a mutable reference generic binary value for this key if it exists and has the correct type.
Sourcepub fn get_object_id(&self, key: &str) -> Result<&ObjectId, ValueAccessError>
pub fn get_object_id(&self, key: &str) -> Result<&ObjectId, ValueAccessError>
Get a reference to an object id value for this key if it exists and has the correct type.
Sourcepub fn get_object_id_mut(
&mut self,
key: &str,
) -> Result<&mut ObjectId, ValueAccessError>
pub fn get_object_id_mut( &mut self, key: &str, ) -> Result<&mut ObjectId, ValueAccessError>
Get a mutable reference to an object id value for this key if it exists and has the correct type.
Sourcepub fn get_datetime(
&self,
key: &str,
) -> Result<&DateTime<Utc>, ValueAccessError>
pub fn get_datetime( &self, key: &str, ) -> Result<&DateTime<Utc>, ValueAccessError>
Get a reference to a UTC datetime value for this key if it exists and has the correct type.
Sourcepub fn get_datetime_mut(
&mut self,
key: &str,
) -> Result<&mut DateTime<Utc>, ValueAccessError>
pub fn get_datetime_mut( &mut self, key: &str, ) -> Result<&mut DateTime<Utc>, ValueAccessError>
Get a mutable reference to a UTC datetime value for this key if it exists and has the correct type.
Sourcepub fn contains_key(&self, key: &str) -> bool
pub fn contains_key(&self, key: &str) -> bool
Returns true if the map contains a value for the specified key.
Sourcepub fn insert<KT, BT>(&mut self, key: KT, val: BT) -> Option<Bson>
pub fn insert<KT, BT>(&mut self, key: KT, val: BT) -> Option<Bson>
Sets the value of the entry with the OccupiedEntry’s key, and returns the entry’s old value. Accepts any type that can be converted into Bson.
Sourcepub fn remove(&mut self, key: &str) -> Option<Bson>
pub fn remove(&mut self, key: &str) -> Option<Bson>
Takes the value of the entry out of the document, and returns it.
pub fn entry(&mut self, k: String) -> Entry<'_>
Sourcepub fn to_writer<W>(&self, writer: &mut W) -> Result<(), Error>
pub fn to_writer<W>(&self, writer: &mut W) -> Result<(), Error>
Attempts to serialize the Document
into a byte stream.
Sourcepub fn from_reader<R>(reader: &mut R) -> Result<Document, Error>
pub fn from_reader<R>(reader: &mut R) -> Result<Document, Error>
Attempts to deserialize a Document
from a byte stream.
Sourcepub fn from_reader_utf8_lossy<R>(reader: &mut R) -> Result<Document, Error>
pub fn from_reader_utf8_lossy<R>(reader: &mut R) -> Result<Document, Error>
Attempt to deserialize a Document
that may contain invalid UTF-8 strings from a byte
stream.
This is mainly useful when reading raw BSON returned from a MongoDB server, which
in rare cases can contain invalidly truncated strings (https://jira.mongodb.org/browse/SERVER-24007).
For most use cases, Document::from_reader
can be used instead.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Document
impl<'de> Deserialize<'de> for Document
Source§fn deserialize<D>(
deserializer: D,
) -> Result<Document, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<Document, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Deserialize this value given this Deserializer
.
Source§impl Extend<(String, Bson)> for Document
impl Extend<(String, Bson)> for Document
Source§fn extend<T>(&mut self, iter: T)
fn extend<T>(&mut self, iter: T)
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Source§impl From<Document> for UpdateModifications
impl From<Document> for UpdateModifications
Source§fn from(item: Document) -> UpdateModifications
fn from(item: Document) -> UpdateModifications
Source§impl<'a> IntoIterator for &'a Document
impl<'a> IntoIterator for &'a Document
Source§impl IntoIterator for Document
impl IntoIterator for Document
Source§impl Serialize for Document
impl Serialize for Document
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Source§impl TryFrom<Map<String, Value>> for Document
This converts from the input JSON as if it were MongoDB Extended JSON v2.
impl TryFrom<Map<String, Value>> for Document
This converts from the input JSON as if it were MongoDB Extended JSON v2.