Table of Contents

Class BsonObjectId

Namespace
MongoDB.Bson
Assembly
MongoDB.Bson.dll

Represents a BSON ObjectId value (see also ObjectId).

[Serializable]
public class BsonObjectId : BsonValue, IComparable<BsonValue>, IConvertible, IEquatable<BsonValue>, IComparable<BsonObjectId>, IEquatable<BsonObjectId>
Inheritance
BsonObjectId
Implements
Inherited Members
Extension Methods

Constructors

BsonObjectId(ObjectId)

Initializes a new instance of the BsonObjectId class.

public BsonObjectId(ObjectId value)

Parameters

value ObjectId

The value.

BsonObjectId(byte[])

Initializes a new instance of the BsonObjectId class.

[Obsolete("Use new BsonObjectId(ObjectId value) instead.")]
public BsonObjectId(byte[] bytes)

Parameters

bytes byte[]

The bytes.

BsonObjectId(DateTime, int, short, int)

Initializes a new instance of the BsonObjectId class.

[Obsolete("Use new BsonObjectId(new ObjectId(DateTime timestamp, int machine, short pid, int increment)) instead.")]
public BsonObjectId(DateTime timestamp, int machine, short pid, int increment)

Parameters

timestamp DateTime

The timestamp (expressed as a DateTime).

machine int

The machine hash.

pid short

The PID.

increment int

The increment.

BsonObjectId(int, int, short, int)

Initializes a new instance of the BsonObjectId class.

[Obsolete("Use new BsonObjectId(new ObjectId(int timestamp, int machine, short pid, int increment)) instead.")]
public BsonObjectId(int timestamp, int machine, short pid, int increment)

Parameters

timestamp int

The timestamp.

machine int

The machine hash.

pid short

The PID.

increment int

The increment.

BsonObjectId(string)

Initializes a new instance of the BsonObjectId class.

[Obsolete("Use new BsonObjectId(new ObjectId(string value)) instead.")]
public BsonObjectId(string value)

Parameters

value string

The value.

Properties

BsonType

Gets the BsonType of this BsonValue.

public override BsonType BsonType { get; }

Property Value

BsonType

CreationTime

Gets the creation time (derived from the timestamp).

[Obsolete("Use Value.CreationTime instead.")]
public DateTime CreationTime { get; }

Property Value

DateTime

Empty

Gets an instance of BsonObjectId where the value is empty.

public static BsonObjectId Empty { get; }

Property Value

BsonObjectId

Increment

Gets the increment.

[Obsolete("Use Value.Increment instead.")]
public int Increment { get; }

Property Value

int

Machine

Gets the machine.

[Obsolete("This property will be removed in a later release.")]
public int Machine { get; }

Property Value

int

Pid

Gets the PID.

[Obsolete("This property will be removed in a later release.")]
public short Pid { get; }

Property Value

short

RawValue

Gets the BsonObjectId as an ObjectId.

[Obsolete("Use Value instead.")]
public override object RawValue { get; }

Property Value

object

Timestamp

Gets the timestamp.

[Obsolete("Use Value.Timestamp instead.")]
public int Timestamp { get; }

Property Value

int

Value

Gets the value of this BsonObjectId.

public ObjectId Value { get; }

Property Value

ObjectId

Methods

CompareTo(BsonObjectId)

Compares this BsonObjectId to another BsonObjectId.

public int CompareTo(BsonObjectId other)

Parameters

other BsonObjectId

The other BsonObjectId.

Returns

int

A 32-bit signed integer that indicates whether this BsonObjectId is less than, equal to, or greather than the other.

CompareTo(BsonValue)

Compares the BsonObjectId to another BsonValue.

public override int CompareTo(BsonValue other)

Parameters

other BsonValue

The other BsonValue.

Returns

int

A 32-bit signed integer that indicates whether this BsonObjectId is less than, equal to, or greather than the other BsonValue.

Create(object)

Creates a new BsonObjectId.

public static BsonObjectId Create(object value)

Parameters

value object

An object to be mapped to a BsonObjectId.

Returns

BsonObjectId

A BsonObjectId or null.

Equals(BsonObjectId)

Compares this BsonObjectId to another BsonObjectId.

public bool Equals(BsonObjectId rhs)

Parameters

rhs BsonObjectId

The other BsonObjectId.

Returns

bool

True if the two BsonObjectId values are equal.

Equals(object)

Compares this BsonObjectId to another object.

public override bool Equals(object obj)

Parameters

obj object

The other object.

Returns

bool

True if the other object is a BsonObjectId and equal to this one.

GenerateNewId()

Generates a new BsonObjectId with a unique value.

[Obsolete("Use new BsonObjectId(ObjectId.GenerateNewId()) instead.")]
public static BsonObjectId GenerateNewId()

Returns

BsonObjectId

A BsonObjectId.

GenerateNewId(DateTime)

Generates a new BsonObjectId with a unique value (with the timestamp component based on a given DateTime).

[Obsolete("Use new BsonObjectId(ObjectId.GenerateNewId(DateTime timestamp)) instead.")]
public static BsonObjectId GenerateNewId(DateTime timestamp)

Parameters

timestamp DateTime

The timestamp component (expressed as a DateTime).

Returns

BsonObjectId

A BsonObjectId.

GenerateNewId(int)

Generates a new BsonObjectId with a unique value (with the given timestamp).

[Obsolete("Use new BsonObjectId(ObjectId.GenerateNewId(int timestamp)) instead.")]
public static BsonObjectId GenerateNewId(int timestamp)

Parameters

timestamp int

The timestamp component.

Returns

BsonObjectId

A BsonObjectId.

GetHashCode()

Gets the hash code.

public override int GetHashCode()

Returns

int

The hash code.

IConvertibleToStringImplementation(IFormatProvider)

Implementation of the IConvertible ToString method.

protected override string IConvertibleToStringImplementation(IFormatProvider provider)

Parameters

provider IFormatProvider

The format provider.

Returns

string

A string.

Parse(string)

Parses a string and creates a new BsonObjectId.

[Obsolete("Use new BsonObjectId(ObjectId.Parse(string s)) instead.")]
public static BsonObjectId Parse(string s)

Parameters

s string

The string value.

Returns

BsonObjectId

A BsonObjectId.

ToByteArray()

Converts the BsonObjectId to a byte array.

[Obsolete("Use Value.ToByteArray() instead.")]
public byte[] ToByteArray()

Returns

byte[]

A byte array.

ToString()

Returns a string representation of the value.

public override string ToString()

Returns

string

A string representation of the value.

TryParse(string, out BsonObjectId)

Tries to parse a string and create a new BsonObjectId.

[Obsolete("Use ObjectId.TryParse instead.")]
public static bool TryParse(string s, out BsonObjectId value)

Parameters

s string

The string value.

value BsonObjectId

The new BsonObjectId.

Returns

bool

True if the string was parsed successfully.

Operators

operator ==(BsonObjectId, BsonObjectId)

Compares two BsonObjectId values.

public static bool operator ==(BsonObjectId lhs, BsonObjectId rhs)

Parameters

lhs BsonObjectId

The first BsonObjectId.

rhs BsonObjectId

The other BsonObjectId.

Returns

bool

True if the two BsonObjectId values are equal according to ==.

implicit operator BsonObjectId(ObjectId)

Converts an ObjectId to a BsonObjectId.

public static implicit operator BsonObjectId(ObjectId value)

Parameters

value ObjectId

An ObjectId.

Returns

BsonObjectId

A BsonObjectId.

operator !=(BsonObjectId, BsonObjectId)

Compares two BsonObjectId values.

public static bool operator !=(BsonObjectId lhs, BsonObjectId rhs)

Parameters

lhs BsonObjectId

The first BsonObjectId.

rhs BsonObjectId

The other BsonObjectId.

Returns

bool

True if the two BsonObjectId values are not equal according to ==.