Table of Contents

Struct ObjectId

Namespace
MongoDB.Bson
Assembly
MongoDB.Bson.dll

Represents an ObjectId (see also BsonObjectId).

[Serializable]
public struct ObjectId : IComparable<ObjectId>, IEquatable<ObjectId>, IConvertible
Implements
Inherited Members
Extension Methods

Constructors

ObjectId(byte[])

Initializes a new instance of the ObjectId class.

public ObjectId(byte[] bytes)

Parameters

bytes byte[]

The bytes.

ObjectId(DateTime, int, short, int)

Initializes a new instance of the ObjectId class.

[Obsolete("This constructor will be removed in a later release.")]
public ObjectId(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.

ObjectId(int, int, short, int)

Initializes a new instance of the ObjectId class.

[Obsolete("This constructor will be removed in a later release.")]
public ObjectId(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.

ObjectId(string)

Initializes a new instance of the ObjectId class.

public ObjectId(string value)

Parameters

value string

The value.

Properties

CreationTime

Gets the creation time (derived from the timestamp).

public DateTime CreationTime { get; }

Property Value

DateTime

Empty

Gets an instance of ObjectId where the value is empty.

public static ObjectId Empty { get; }

Property Value

ObjectId

Increment

Gets the increment.

[Obsolete("This property will be removed in a later release.")]
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

Timestamp

Gets the timestamp.

public int Timestamp { get; }

Property Value

int

Methods

CompareTo(ObjectId)

Compares this ObjectId to another ObjectId.

public int CompareTo(ObjectId other)

Parameters

other ObjectId

The other ObjectId.

Returns

int

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

Equals(ObjectId)

Compares this ObjectId to another ObjectId.

public bool Equals(ObjectId rhs)

Parameters

rhs ObjectId

The other ObjectId.

Returns

bool

True if the two ObjectIds are equal.

Equals(object)

Compares this ObjectId to another object.

public override bool Equals(object obj)

Parameters

obj object

The other object.

Returns

bool

True if the other object is an ObjectId and equal to this one.

GenerateNewId()

Generates a new ObjectId with a unique value.

public static ObjectId GenerateNewId()

Returns

ObjectId

An ObjectId.

GenerateNewId(DateTime)

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

public static ObjectId GenerateNewId(DateTime timestamp)

Parameters

timestamp DateTime

The timestamp component (expressed as a DateTime).

Returns

ObjectId

An ObjectId.

GenerateNewId(int)

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

public static ObjectId GenerateNewId(int timestamp)

Parameters

timestamp int

The timestamp component.

Returns

ObjectId

An ObjectId.

GetHashCode()

Gets the hash code.

public override int GetHashCode()

Returns

int

The hash code.

Pack(int, int, short, int)

Packs the components of an ObjectId into a byte array.

[Obsolete("This method will be removed in a later release.")]
public static byte[] Pack(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.

Returns

byte[]

A byte array.

Parse(string)

Parses a string and creates a new ObjectId.

public static ObjectId Parse(string s)

Parameters

s string

The string value.

Returns

ObjectId

A ObjectId.

ToByteArray()

Converts the ObjectId to a byte array.

public byte[] ToByteArray()

Returns

byte[]

A byte array.

ToByteArray(byte[], int)

Converts the ObjectId to a byte array.

public void ToByteArray(byte[] destination, int offset)

Parameters

destination byte[]

The destination.

offset int

The offset.

ToString()

Returns a string representation of the value.

public override string ToString()

Returns

string

A string representation of the value.

TryParse(string, out ObjectId)

Tries to parse a string and create a new ObjectId.

public static bool TryParse(string s, out ObjectId objectId)

Parameters

s string

The string value.

objectId ObjectId

The new ObjectId.

Returns

bool

True if the string was parsed successfully.

Unpack(byte[], out int, out int, out short, out int)

Unpacks a byte array into the components of an ObjectId.

[Obsolete("This method will be removed in a later release.")]
public static void Unpack(byte[] bytes, out int timestamp, out int machine, out short pid, out int increment)

Parameters

bytes byte[]

A byte array.

timestamp int

The timestamp.

machine int

The machine hash.

pid short

The PID.

increment int

The increment.

Operators

operator ==(ObjectId, ObjectId)

Compares two ObjectIds.

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

Parameters

lhs ObjectId

The first ObjectId.

rhs ObjectId

The other ObjectId.

Returns

bool

True if the two ObjectIds are equal.

operator >(ObjectId, ObjectId)

Compares two ObjectIds.

public static bool operator >(ObjectId lhs, ObjectId rhs)

Parameters

lhs ObjectId

The first ObjectId.

rhs ObjectId

The other ObjectId

Returns

bool

True if the first ObjectId is greather than the second ObjectId.

operator >=(ObjectId, ObjectId)

Compares two ObjectIds.

public static bool operator >=(ObjectId lhs, ObjectId rhs)

Parameters

lhs ObjectId

The first ObjectId.

rhs ObjectId

The other ObjectId

Returns

bool

True if the first ObjectId is greather than or equal to the second ObjectId.

operator !=(ObjectId, ObjectId)

Compares two ObjectIds.

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

Parameters

lhs ObjectId

The first ObjectId.

rhs ObjectId

The other ObjectId.

Returns

bool

True if the two ObjectIds are not equal.

operator <(ObjectId, ObjectId)

Compares two ObjectIds.

public static bool operator <(ObjectId lhs, ObjectId rhs)

Parameters

lhs ObjectId

The first ObjectId.

rhs ObjectId

The other ObjectId

Returns

bool

True if the first ObjectId is less than the second ObjectId.

operator <=(ObjectId, ObjectId)

Compares two ObjectIds.

public static bool operator <=(ObjectId lhs, ObjectId rhs)

Parameters

lhs ObjectId

The first ObjectId.

rhs ObjectId

The other ObjectId

Returns

bool

True if the first ObjectId is less than or equal to the second ObjectId.