SequentialGuid.MongoDB
5.0.7
dotnet add package SequentialGuid.MongoDB --version 5.0.7
NuGet\Install-Package SequentialGuid.MongoDB -Version 5.0.7
<PackageReference Include="SequentialGuid.MongoDB" Version="5.0.7" />
<PackageVersion Include="SequentialGuid.MongoDB" Version="5.0.7" />
<PackageReference Include="SequentialGuid.MongoDB" />
paket add SequentialGuid.MongoDB --version 5.0.7
#r "nuget: SequentialGuid.MongoDB, 5.0.7"
#:package SequentialGuid.MongoDB@5.0.7
#addin nuget:?package=SequentialGuid.MongoDB&version=5.0.7
#tool nuget:?package=SequentialGuid.MongoDB&version=5.0.7
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.
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. |
| .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 (>= 5.0.7)
-
.NETStandard 2.0
- MongoDB.Bson (>= 2.29.0)
- SequentialGuid (>= 5.0.7)
-
net10.0
- MongoDB.Bson (>= 2.29.0)
- SequentialGuid (>= 5.0.7)
-
net8.0
- MongoDB.Bson (>= 2.29.0)
- SequentialGuid (>= 5.0.7)
-
net9.0
- MongoDB.Bson (>= 2.29.0)
- SequentialGuid (>= 5.0.7)
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 |