SequentialGuid.MongoDB
6.2.0
dotnet add package SequentialGuid.MongoDB --version 6.2.0
NuGet\Install-Package SequentialGuid.MongoDB -Version 6.2.0
<PackageReference Include="SequentialGuid.MongoDB" Version="6.2.0" />
<PackageVersion Include="SequentialGuid.MongoDB" Version="6.2.0" />
<PackageReference Include="SequentialGuid.MongoDB" />
paket add SequentialGuid.MongoDB --version 6.2.0
#r "nuget: SequentialGuid.MongoDB, 6.2.0"
#:package SequentialGuid.MongoDB@6.2.0
#addin nuget:?package=SequentialGuid.MongoDB&version=6.2.0
#tool nuget:?package=SequentialGuid.MongoDB&version=6.2.0
SequentialGuid.MongoDB
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.Bson2.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
MongoSequentialGuidGeneratorimplementsIIdGeneratorand callsGuidV8Time.NewGuid()to generate each ID. It considers anyGuidvalue that is notGuid.Emptyas non-empty.SequentialGuidSerializer<T>delegates to the defaultGuidBSON serializer for the wire format, then wraps/unwraps the struct type on read/write. This means documents stored with rawGuidIDs remain compatible.
Choosing the GUID version
MongoSequentialGuidGenerator.Instance emits RFC 9562 v8 time-based GUIDs — the historical default, preserving full 100 ns tick precision in the document id. To emit v7 ids instead:
new MongoSequentialGuidGenerator(SequentialGuidType.Rfc9562V7).RegisterMongoIdGenerator();
The default stays v8 so existing applications keep their id semantics across upgrades.
Further Reading
See the main SequentialGuid README for full documentation on UUID generation, timestamp extraction, and SQL Server byte-order handling.
| Product | Versions 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. net11.0 is compatible. |
| .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. |
-
.NETFramework 4.6.2
- MongoDB.Bson (>= 2.29.0)
- SequentialGuid (>= 6.2.0)
-
.NETStandard 2.0
- MongoDB.Bson (>= 2.29.0)
- SequentialGuid (>= 6.2.0)
-
net10.0
- MongoDB.Bson (>= 2.29.0)
- SequentialGuid (>= 6.2.0)
-
net11.0
- MongoDB.Bson (>= 2.29.0)
- SequentialGuid (>= 6.2.0)
-
net8.0
- MongoDB.Bson (>= 2.29.0)
- SequentialGuid (>= 6.2.0)
-
net9.0
- MongoDB.Bson (>= 2.29.0)
- SequentialGuid (>= 6.2.0)
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 |
|---|---|---|
| 6.2.0 | 0 | 6/10/2026 |
| 6.1.0 | 102 | 5/13/2026 |
| 6.0.0 | 96 | 5/12/2026 |
| 5.0.7 | 122 | 3/21/2026 |
| 5.0.6 | 110 | 3/18/2026 |
| 5.0.5 | 111 | 3/17/2026 |
| 5.0.4 | 119 | 3/17/2026 |
| 5.0.3 | 121 | 3/13/2026 |
| 5.0.2 | 115 | 3/9/2026 |
| 4.0.6 | 244 | 2/19/2025 |
| 4.0.5 | 246 | 3/20/2024 |
| 4.0.4 | 417 | 2/27/2023 |
| 4.0.3 | 554 | 10/25/2022 |
| 4.0.2 | 569 | 10/20/2022 |
| 4.0.1 | 567 | 10/10/2022 |
| 4.0.0 | 531 | 10/5/2022 |
| 3.0.1 | 666 | 2/22/2022 |
| 3.0.0 | 583 | 9/15/2021 |