SequentialGuid.MongoDB 5.0.7

dotnet add package SequentialGuid.MongoDB --version 5.0.7
                    
NuGet\Install-Package SequentialGuid.MongoDB -Version 5.0.7
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SequentialGuid.MongoDB" Version="5.0.7" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SequentialGuid.MongoDB" Version="5.0.7" />
                    
Directory.Packages.props
<PackageReference Include="SequentialGuid.MongoDB" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add SequentialGuid.MongoDB --version 5.0.7
                    
#r "nuget: SequentialGuid.MongoDB, 5.0.7"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package SequentialGuid.MongoDB@5.0.7
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=SequentialGuid.MongoDB&version=5.0.7
                    
Install as a Cake Addin
#tool nuget:?package=SequentialGuid.MongoDB&version=5.0.7
                    
Install as a Cake Tool

SequentialGuid.MongoDB

NuGet NuGet Downloads

MongoDB integration for the SequentialGuid library. Provides a drop-in IIdGenerator for automatic sequential Guid document IDs and BSON serializers for the SequentialGuid / SequentialSqlGuid struct types.

Install

dotnet add package SequentialGuid.MongoDB

Requires MongoDB.Bson 2.29.0 or later.

Features

Feature Description
MongoSequentialGuidGenerator IIdGenerator implementation - generates sequential Guid IDs for documents automatically
BSON serializers Transparent serialization of SequentialGuid and SequentialSqlGuid (including nullable variants)

Quick Start

1. Register the ID generator

Register the singleton generator so MongoDB uses sequential GUIDs for all Guid id properties:

using SequentialGuid.MongoDB;

// Register as the default Guid id generator
MongoSequentialGuidGenerator.Instance.RegisterMongoIdGenerator();

2. Register the BSON serializers

If your documents use SequentialGuid or SequentialSqlGuid as property types (not just raw Guid), register the serialization provider:

using MongoDB.Bson.Serialization;
using SequentialGuid.MongoDB.Serializers;

BsonSerializer.RegisterSequentialGuidSerializers();

This registers serializers for SequentialGuid, SequentialGuid?, SequentialSqlGuid, and SequentialSqlGuid?.

3. Use in your document models

Option A - Raw Guid with automatic generation:

public class Order
{
    public Guid Id { get; set; }

    public string Description { get; set; } = string.Empty;
}

// Insert - Id is generated automatically by MongoSequentialGuidGenerator
await collection.InsertOneAsync(new Order { Description = "Widget" });

Option B - Strongly-typed struct properties:

using SequentialGuid;

public class Order
{
    public SequentialGuid Id { get; set; } = new();

    // Timestamp is always available from the ID itself
    public DateTime? CreatedAt => Id.Timestamp;

    public string Description { get; set; } = string.Empty;
}

Complete setup example

using MongoDB.Bson.Serialization;
using MongoDB.Driver;
using SequentialGuid.MongoDB;
using SequentialGuid.MongoDB.Serializers;

// One-time setup (typically in Program.cs or a startup class)
MongoSequentialGuidGenerator.Instance.RegisterMongoIdGenerator();
BsonSerializer.RegisterSequentialGuidSerializers();

// Use MongoDB as normal
var client = new MongoClient("mongodb://localhost:27017");
var db = client.GetDatabase("myapp");
var orders = db.GetCollection<Order>("orders");

await orders.InsertOneAsync(new Order { Description = "Widget" });

How It Works

  • MongoSequentialGuidGenerator implements IIdGenerator and calls GuidV8Time.NewGuid() to generate each ID. It considers any Guid value that is not Guid.Empty as non-empty.
  • SequentialGuidSerializer<T> delegates to the default Guid BSON serializer for the wire format, then wraps/unwraps the struct type on read/write. This means documents stored with raw Guid IDs remain compatible.

Further Reading

See the main SequentialGuid README for full documentation on UUID generation, timestamp extraction, and SQL Server byte-order handling.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
5.0.7 85 3/21/2026
5.0.6 84 3/18/2026
5.0.5 82 3/17/2026
5.0.4 95 3/17/2026
5.0.3 93 3/13/2026
5.0.2 90 3/9/2026
4.0.6 231 2/19/2025
4.0.5 230 3/20/2024
4.0.4 406 2/27/2023
4.0.3 542 10/25/2022
4.0.2 558 10/20/2022
4.0.1 551 10/10/2022
4.0.0 519 10/5/2022
3.0.1 656 2/22/2022
3.0.0 568 9/15/2021
2.5.0 664 11/18/2020