Table of Contents

Class BsonDocument

Namespace
MongoDB.Bson
Assembly
MongoDB.Bson.dll

Represents a BSON document.

public class BsonDocument : BsonValue, IComparable<BsonValue>, IConvertible, IEquatable<BsonValue>, IComparable<BsonDocument>, IConvertibleToBsonDocument, IEnumerable<BsonElement>, IEnumerable, IEquatable<BsonDocument>
Inheritance
BsonDocument
Implements
Derived
Inherited Members
Extension Methods

Constructors

BsonDocument()

Initializes a new instance of the BsonDocument class.

BsonDocument(BsonDocument)

Initializes a new instance of the BsonDocument by coping elements from another BsonDocument.

BsonDocument(BsonElement)

Initializes a new instance of the BsonDocument class and adds one element.

BsonDocument(params BsonElement[])

Initializes a new instance of the BsonDocument class and adds one or more elements.

BsonDocument(bool)

Initializes a new instance of the BsonDocument class specifying whether duplicate element names are allowed (allowing duplicate element names is not recommended).

BsonDocument(Dictionary<string, object>)

Initializes a new instance of the BsonDocument class and adds new elements from a dictionary of key/value pairs.

BsonDocument(IEnumerable<BsonElement>)

Initializes a new instance of the BsonDocument class and adds new elements from a list of elements.

BsonDocument(IEnumerable<KeyValuePair<string, object>>)

Initializes a new instance of the BsonDocument class and adds new elements from a dictionary of key/value pairs.

BsonDocument(IDictionary)

Initializes a new instance of the BsonDocument class and adds new elements from a dictionary of key/value pairs.

BsonDocument(string, BsonValue)

Initializes a new instance of the BsonDocument class and creates and adds a new element.

Properties

AllowDuplicateNames

Gets or sets whether to allow duplicate names (allowing duplicate names is not recommended).

BsonType

Gets the BsonType of this BsonValue.

ElementCount

Gets the number of elements.

Elements

Gets the elements.

this[int]

Gets or sets a value by position.

this[string]

Gets or sets a value by name.

Names

Gets the element names.

Values

Gets the values.

Methods

Add(BsonElement)

Adds an element to the document.

Add(string, BsonValue)

Creates and adds an element to the document.

Add(string, BsonValue, bool)

Creates and adds an element to the document, but only if the condition is true.

Add(string, Func<BsonValue>, bool)

Creates and adds an element to the document, but only if the condition is true. If the condition is false the value factory is not called at all.

AddRange(Dictionary<string, object>)

Adds elements to the document from a dictionary of key/value pairs.

AddRange(IEnumerable<BsonElement>)

Adds a list of elements to the document.

AddRange(IEnumerable<KeyValuePair<string, object>>)

Adds elements to the document from a dictionary of key/value pairs.

AddRange(IDictionary)

Adds elements to the document from a dictionary of key/value pairs.

Clear()

Clears the document (removes all elements).

Clone()

Creates a shallow clone of the document (see also DeepClone).

CompareTo(BsonDocument)

Compares this document to another document.

CompareTo(BsonValue)

Compares the BsonDocument to another BsonValue.

Contains(string)

Tests whether the document contains an element with the specified name.

ContainsValue(BsonValue)

Tests whether the document contains an element with the specified value.

Create(object)

Creates a new BsonDocument by mapping an object to a BsonDocument.

DeepClone()

Creates a deep clone of the document (see also Clone).

Equals(BsonDocument)

Compares this document to another document.

Equals(object)

Compares this BsonDocument to another object.

GetElement(int)

Gets an element of this document.

GetElement(string)

Gets an element of this document.

GetEnumerator()

Gets an enumerator that can be used to enumerate the elements of this document.

GetHashCode()

Gets the hash code.

GetValue(int)

Gets the value of an element.

GetValue(string)

Gets the value of an element.

GetValue(string, BsonValue)

Gets the value of an element or a default value if the element is not found.

IndexOfName(string)

Gets the index of an element.

InsertAt(int, BsonElement)

Inserts a new element at a specified position.

Merge(BsonDocument)

Merges another document into this one. Existing elements are not overwritten.

Merge(BsonDocument, bool)

Merges another document into this one, specifying whether existing elements are overwritten.

Parse(string)

Parses a JSON string and returns a BsonDocument.

Remove(string)

Removes an element from this document (if duplicate element names are allowed then all elements with this name will be removed).

RemoveAt(int)

Removes an element from this document.

RemoveElement(BsonElement)

Removes an element from this document.

Set(int, BsonValue)

Sets the value of an element.

Set(string, BsonValue)

Sets the value of an element (an element will be added if no element with this name is found).

SetElement(BsonElement)

Sets an element of the document (replaces any existing element with the same name or adds a new element if an element with the same name is not found).

SetElement(int, BsonElement)

Sets an element of the document (replacing the existing element at that position).

ToDictionary()

Converts the BsonDocument to a Dictionary<string, object>.

ToHashtable()

Converts the BsonDocument to a Hashtable.

ToString()

Returns a string representation of the document.

TryGetElement(string, out BsonElement)

Tries to get an element of this document.

TryGetValue(string, out BsonValue)

Tries to get the value of an element of this document.

TryParse(string, out BsonDocument)

Tries to parse a JSON string and returns a value indicating whether it succeeded or failed.

Operators

operator ==(BsonDocument, BsonDocument)

Compares two BsonDocument values.

operator !=(BsonDocument, BsonDocument)

Compares two BsonDocument values.