Table of Contents

Class AscendingGuidGenerator

Namespace
MongoDB.Bson.Serialization.IdGenerators
Assembly
MongoDB.Bson.dll

A GUID generator that generates GUIDs in ascending order. To enable an index to make use of the ascending nature make sure to use GuidRepresentation.Standard as the storage representation. Internally the GUID is of the form 8 bytes: Ticks from DateTime.UtcNow.Ticks 5 bytes: Random value from ObjectId spec 3 bytes: increment

public class AscendingGuidGenerator : IIdGenerator
Inheritance
AscendingGuidGenerator
Implements
Inherited Members
Extension Methods

Properties

Instance

Gets an instance of AscendingGuidGenerator.

public static AscendingGuidGenerator Instance { get; }

Property Value

AscendingGuidGenerator

Methods

GenerateId(long, byte[], int)

Generates a Guid for a document. Note - this is purely used for unit testing

public object GenerateId(long tickCount, byte[] machineProcessId, int increment)

Parameters

tickCount long

The time portion of the Guid

machineProcessId byte[]

A 5 byte array with the first 3 bytes representing a machine id and the next 2 representing a process id

increment int

The increment portion of the Guid. Used to distinguish between 2 Guids that have the timestamp. Note only the least significant 3 bytes are used.

Returns

object

A Guid.

GenerateId(object, object)

Generates an ascending Guid for a document. Consecutive invocations should generate Guids that are ascending from a MongoDB perspective

public object GenerateId(object container, object document)

Parameters

container object

The container of the document (will be a MongoCollection when called from the driver).

document object

The document it was generated for.

Returns

object

A Guid.

IsEmpty(object)

Tests whether an id is empty.

public bool IsEmpty(object id)

Parameters

id object

The id to test.

Returns

bool

True if the Id is empty. False otherwise