Struct bson::document::Document [−][src]
pub struct Document { /* fields omitted */ }
Expand description
A BSON document represented as an associative HashMap with insertion ordering.
Implementations
Gets an iterator over the entries of the map.
Returns a reference to the Bson corresponding to the key.
Gets a mutable reference to the Bson corresponding to the key
Get a floating point value for this key if it exists and has the correct type.
Get a mutable reference to a floating point value for this key if it exists and has the correct type.
Get a reference to a Decimal128 value for key, if it exists.
pub fn get_decimal128_mut(
&mut self,
key: impl AsRef<str>
) -> ValueAccessResult<&mut Decimal128>
pub fn get_decimal128_mut(
&mut self,
key: impl AsRef<str>
) -> ValueAccessResult<&mut Decimal128>
Get a mutable reference to a Decimal128 value for key, if it exists.
Get a string slice this key if it exists and has the correct type.
Get a mutable string slice this key if it exists and has the correct type.
Get a reference to an array for this key if it exists and has the correct type.
Get a mutable reference to an array for this key if it exists and has the correct type.
Get a reference to a document for this key if it exists and has the correct type.
Get a mutable reference to a document for this key if it exists and has the correct type.
Get a bool value for this key if it exists and has the correct type.
Get a mutable reference to a bool value for this key if it exists and has the correct type.
Get an i32 value for this key if it exists and has the correct type.
Get a mutable reference to an i32 value for this key if it exists and has the correct type.
Get an i64 value for this key if it exists and has the correct type.
Get a mutable reference to an i64 value for this key if it exists and has the correct type.
Get a time stamp value for this key if it exists and has the correct type.
pub fn get_timestamp_mut(
&mut self,
key: impl AsRef<str>
) -> ValueAccessResult<&mut Timestamp>
pub fn get_timestamp_mut(
&mut self,
key: impl AsRef<str>
) -> ValueAccessResult<&mut Timestamp>
Get a mutable reference to a time stamp value for this key if it exists and has the correct type.
Get a reference to a generic binary value for this key if it exists and has the correct type.
pub fn get_binary_generic_mut(
&mut self,
key: impl AsRef<str>
) -> ValueAccessResult<&mut Vec<u8>>
pub fn get_binary_generic_mut(
&mut self,
key: impl AsRef<str>
) -> ValueAccessResult<&mut Vec<u8>>
Get a mutable reference generic binary value for this key if it exists and has the correct type.
Get an object id value for this key if it exists and has the correct type.
Get a mutable reference to an object id value for this key if it exists and has the correct type.
Get a reference to a UTC datetime value for this key if it exists and has the correct type.
Get a mutable reference to a UTC datetime value for this key if it exists and has the correct type.
Returns true if the map contains a value for the specified key.
Gets a collection of all keys in the document.
Gets a collection of all values in the document.
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.
Takes the value of the entry out of the document, and returns it. Computes in O(n) time (average).
Attempts to serialize the Document
into a byte stream.
While the method signature indicates an owned writer must be passed in, a mutable reference
may also be passed in due to blanket implementations of Write
provided in the standard
library.
use bson::doc;
let mut v: Vec<u8> = Vec::new();
let doc = doc! { "x" : 1 };
doc.to_writer(&mut v)?;
Attempts to deserialize a Document
from a byte stream.
While the method signature indicates an owned reader must be passed in, a mutable reference
may also be passed in due to blanket implementations of Read
provided in the standard
library.
use bson::{doc, Document};
use std::io::Cursor;
let mut v: Vec<u8> = Vec::new();
let doc = doc! { "x" : 1 };
doc.to_writer(&mut v)?;
// read from mutable reference
let mut reader = Cursor::new(v.clone());
let doc1 = Document::from_reader(&mut reader)?;
// read from owned value
let doc2 = Document::from_reader(Cursor::new(v))?;
assert_eq!(doc, doc1);
assert_eq!(doc, doc2);
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
Deserialize this value given this Deserializer
.
Extends a collection with the contents of an iterator. Read more
extend_one
)Extends a collection with exactly one element.
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
This converts from the input JSON as if it were MongoDB Extended JSON v2.
Auto Trait Implementations
impl RefUnwindSafe for Document
impl UnwindSafe for Document
Blanket Implementations
Mutably borrows from an owned value. Read more