mongo-csharp-driver / GridFS
AGENTS.md3.2k starsChanged 4 months agoApache-2.0View on GitHub
GridFS stores binary files in two collections per bucket: <bucket>.files (metadata, one document per file) and <bucket>.chunks (binary data, many documents per file). Chunk size is configurable; default 255 KiB. GridFSBucket holds the cluster reference, an IBsonSerializer<GridFSFileInfo<TFileId>> (_fileInfoSerializer), and a BsonSerializationInfo for the _id field (_idSerializationInfo, which is what enforces the TFileId round-trip discussed in the pitfalls below). Mutating operations (Delete, Rename, OpenUploadStream, Drop) bind via GetSingleServerReadWriteBinding; reads (DownloadAsBytes*, DownloadToStream*, OpenDownloadStream*, Find) bind via GetSingleServerReadBinding. Either way, a single upload/download…
Trending
Quiet since September.about the whole repository
Who's talking about mongodb/mongo-csharp-driver
- jbogard/MongoDB.Driver.Core.Extensions.DiagnosticSources“Support for latest MongoDB library with signing”GitHub · Jul 28, 2024 · 13 reactions
- opensearch-project/opensearch-net“[FEATURE] Add LINQ Support to the OpenSearch C# Client”GitHub · Sep 18, 2023 · 5 reactions
- nopSolutions/nopCommerce“MongoDB database support”GitHub · Apr 30, 2019 · 4 reactions
- microsoft/aspire“MongoDB.Driver v3 breaks Aspire.MongoDB.Driver integration”GitHub · Oct 18, 2024 · 3 reactions
- jbogard/MongoDB.Driver.Core.Extensions.DiagnosticSources“Deprecate this package”GitHub · Apr 21, 2026 · 2 reactions
The biggest 5 of 40 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 40
Talked about on GitHub (40 times).
On GitHub · 40
- Jul 28, 2024Support for latest MongoDB library with signing — jbogard/MongoDB.Driver.Core.Extensions.DiagnosticSources13 reactions · 5 comments
- Sep 18, 2023[FEATURE] Add LINQ Support to the OpenSearch C# Client — opensearch-project/opensearch-net5 reactions · 1 comment
- Apr 30, 2019MongoDB database support — nopSolutions/nopCommerce4 reactions · 24 comments
- Oct 18, 2024MongoDB.Driver v3 breaks Aspire.MongoDB.Driver integration — microsoft/aspire3 reactions · 9 comments
- Apr 21, 2026Deprecate this package — jbogard/MongoDB.Driver.Core.Extensions.DiagnosticSources2 reactions · 1 comment
35 more on GitHub
- Nov 5, 2025Corrected Membership Session Handling — OrleansContrib/Orleans.Providers.MongoDB2 reactions · 2 comments
- Jun 4, 2016Support .NET Core — tugberkugurlu/AspNetCore.Identity.MongoDB2 reactions · 1 comment
- Jul 12, 2026Upgrade MongoDB.Driver to 3.9.0 to fix Snappier and SharpCompress vulnerabilities — madelson/DistributedLock1 reaction
- May 28, 2026Upgrade MongoDB.Driver to 3.9.0 — abpframework/abp1 reaction · 1 comment
- May 12, 2026Upgrade MongoDB.Driver to 3.8.1 — abpframework/abp1 reaction
- Mar 19, 2026bump MongoDB.Driver to 3.7.1 — abpframework/abp1 reaction
- Jan 18, 2026Update MongoDB.Driver package version to 3.6.0 — abpframework/abp1 reaction · 1 comment
- Nov 20, 2025Update MongoDB.Driver to version 3.5.1 — abpframework/abp1 reaction
- Jan 30, 2023Hangfire.Mongo is incompatible with the MongoDB.Driver LINQ3 provider — gottscj/Hangfire.Mongo1 reaction · 1 comment
- Jun 6, 2022Mongo Driver Compatibility — alirezanet/Gridify1 reaction · 3 comments
- Mar 31, 2015Support for 2.0 async driver — RobThree/MongoRepository1 reaction · 35 comments
- Sep 29, 2026Bump MongoDB.Driver from 2.11.5 to 2.19.0 — ramonaoldf/run-devops0 reactions
- Sep 15, 2026Bump the nuget group with 1 update — ApurvSinghal/ApurvXam0 reactions
- Aug 2, 2026Bump MongoDB.Driver from 2.8.1 to 2.19.0 — mohaom/TailwindTraders-Website0 reactions
- Jan 12, 2025Bump MongoDB.Driver from 2.14.1 to 2.19.0 in /src/Infrastructure — vigovlugt/LeagueOfItemsBackend0 reactions
- Aug 6, 2024Update dependency MongoDB.Driver to 2.19.0 [SECURITY] — MrDariusAD/DynamicFilter0 reactions
- Aug 6, 2024Update dependency MongoDB.Driver to 2.12.2 [SECURITY] — ShamKarthikS-Hexaware/recicd0 reactions
- Aug 6, 2024Update dependency MongoDB.Driver to 2.12.2 [SECURITY] — MrDariusAD/GirlfriendAdventskalender0 reactions
- Jan 15, 2024Bump MongoDB.Driver.Core and MongoDB.Bson — kravvya/GardenLog.V20230 reactions
- Nov 17, 2023build(deps): bump MongoDb_Version from 2.19.0 to 2.22.0 — AntonioFalcaoJr/EventualShop0 reactions
- Mar 28, 2023Bump MongoDB.Driver from 2.19.0 to 2.19.1 — eincioch/dotnet-microservices-boilerplate0 reactions
- Mar 27, 2023Bump MongoDB.Driver from 2.19.0 to 2.19.1 — niaz-ali-khan/microservise0 reactions
- Mar 3, 2023Bump MongoDB.Driver from 2.13.1 to 2.19.0 in /DotNet/POC/DatabaseBenchmark — AdamNagy/Nadam.Tryouts0 reactions
- Mar 3, 2023Bump MongoDB.Driver from 2.12.3 to 2.19.0 in /Esiur.Stores.MongoDB — esiur/esiur-dotnet0 reactions
- Oct 17, 2022Bump MongoDB.Driver from 2.17.1 to 2.18.0 in /src/backend — ScottishTapWater/OrderBook0 reactions
- Oct 17, 2022fix(deps): bump MongoDB.Driver from 2.16.1 to 2.18.0 — Manu0912/doppler-push-contact0 reactions
- Oct 17, 2022Bump MongoDB.Driver from 2.13.0 to 2.18.0 — uruk-project/uruk-server0 reactions
- Oct 17, 2022Bump MongoDB.Driver from 2.15.1 to 2.18.0 — joelbyford/ApiPatternsClient0 reactions
- Oct 14, 2022Bump MongoDB.Driver from 2.13.1 to 2.18.0 in /examples/AspNetCoreMvc — brucehu123/opentelemetry-dotnet-instrumentation0 reactions
- Oct 14, 2022Bump MongoDB.Driver from 2.12.4 to 2.18.0 in /services/common/Platform.Common — frogsbreath-games/eucre0 reactions
- Oct 14, 2022Bump MongoDB.Driver from 2.12.4 to 2.18.0 in /services/lobby/Platform.Lobby.Tests — frogsbreath-games/eucre0 reactions
- Oct 14, 2022Bump MongoDB.Driver from 2.12.4 to 2.18.0 in /services/eucre-game/Games.Eucre.Api — frogsbreath-games/eucre0 reactions
- Oct 14, 2022Bump MongoDB.Driver from 2.12.4 to 2.18.0 in /services/weather/Weather.Api — frogsbreath-games/eucre0 reactions
- Oct 14, 2022Bump MongoDB.Driver from 2.12.4 to 2.18.0 in /services/library/Platform.Library.Api — frogsbreath-games/eucre0 reactions
- May 24, 2022Bump MongoDB.Driver from 2.13.1 to 2.15.1 in /examples/AspNetCoreMvc — brucehu123/opentelemetry-dotnet-instrumentation0 reactions
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository35 other files it gives its agents.
- AGENTS.mdAGENTS.md
- src/MongoDB.Bson/AGENTS.mdAGENTS.md
- src/MongoDB.Driver/AGENTS.mdAGENTS.md
- src/MongoDB.Driver/Authentication/AGENTS.mdAGENTS.md
- src/MongoDB.Driver.Authentication.AWS/AGENTS.mdAGENTS.md
- src/MongoDB.Driver/Core/AGENTS.mdAGENTS.md
- src/MongoDB.Driver/Core/Bindings/AGENTS.mdAGENTS.md
- src/MongoDB.Driver/Core/Events/AGENTS.mdAGENTS.md
- src/MongoDB.Driver/Core/Logging/AGENTS.mdAGENTS.md
- src/MongoDB.Driver/Core/Operations/AGENTS.mdAGENTS.md
- src/MongoDB.Driver.Encryption/AGENTS.mdAGENTS.md
- src/MongoDB.Driver/Encryption/AGENTS.mdAGENTS.md
- src/MongoDB.Driver/GeoJsonObjectModel/AGENTS.mdAGENTS.md
- src/MongoDB.Driver/Linq/AGENTS.mdAGENTS.md
- src/MongoDB.Driver/Search/AGENTS.mdAGENTS.md
- tests/MongoDB.Driver.TestHelpers/AGENTS.mdAGENTS.md
- tests/MongoDB.Driver.Tests/Specifications/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- src/MongoDB.Bson/CLAUDE.mdCLAUDE.md
- src/MongoDB.Driver.Authentication.AWS/CLAUDE.mdCLAUDE.md
- src/MongoDB.Driver/Authentication/CLAUDE.mdCLAUDE.md
- src/MongoDB.Driver/CLAUDE.mdCLAUDE.md
- src/MongoDB.Driver/Core/Bindings/CLAUDE.mdCLAUDE.md
- src/MongoDB.Driver/Core/CLAUDE.mdCLAUDE.md
- src/MongoDB.Driver/Core/Events/CLAUDE.mdCLAUDE.md
- src/MongoDB.Driver/Core/Logging/CLAUDE.mdCLAUDE.md
- src/MongoDB.Driver/Core/Operations/CLAUDE.mdCLAUDE.md
- src/MongoDB.Driver.Encryption/CLAUDE.mdCLAUDE.md
- src/MongoDB.Driver/Encryption/CLAUDE.mdCLAUDE.md
- src/MongoDB.Driver/GeoJsonObjectModel/CLAUDE.mdCLAUDE.md
- src/MongoDB.Driver/GridFS/CLAUDE.mdCLAUDE.md
- src/MongoDB.Driver/Linq/CLAUDE.mdCLAUDE.md
- src/MongoDB.Driver/Search/CLAUDE.mdCLAUDE.md
- tests/MongoDB.Driver.TestHelpers/CLAUDE.mdCLAUDE.md
- tests/MongoDB.Driver.Tests/Specifications/CLAUDE.mdCLAUDE.md
The file
We split this AGENTS.md into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 33
Generic file-ID mismatch: If you pick a custom TFileId (not ObjectId), make sure a serializer is registered.
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
GridFS — AGENTS.md
GridFS stores binary files in two collections per bucket: <bucket>.files (metadata, one document per file) and <bucket>.chunks (binary data, many documents per file). Chunk size is configurable; default 255 KiB.
Public API
IGridFSBucket<TFileId>/GridFSBucket<TFileId>— generic over the file ID type. The non-genericIGridFSBucket/GridFSBucketisObjectId-keyed.- Operations:
UploadFromStream,UploadFromBytes,DownloadToStream,DownloadAsBytes,DownloadAsBytesByName,DownloadToStreamByName,OpenUploadStream,OpenDownloadStream,OpenDownloadStreamByName,Find,Delete,Drop,Rename. All have sync + async pairs. Return shapes worth flagging:Findreturns anIAsyncCursor<GridFSFileInfo<TFileId>>(FindAsyncreturns aTask<…>of that),DownloadAsBytes*returns abyte[], andOpenUploadStream*/OpenDownloadStream*return the abstract stream types described below — the upload side returns aGridFSUploadStream<TFileId>whoseIdproperty hands back the allocatedfiles_id. - Streams: the public types are the abstract
StreamsubclassesGridFSUploadStream<TFileId>andGridFSDownloadStream<TFileId>, plus their non-generic compat shimsGridFSUploadStream : DelegatingStreamandGridFSDownloadStream : DelegatingStream(declared inGridFSUploadStreamCompat.cs/GridFSDownloadStreamCompat.cs) — these wrap theObjectId-keyed bucket and are part of the public surface, paralleling theGridFSBucket/GridFSBucket<TFileId>compat split. The concrete runtime implementations —GridFSForwardOnlyUploadStream<TFileId>for uploads, and eitherGridFSForwardOnlyDownloadStream<TFileId>(default) orGridFSSeekableDownloadStream<TFileId>(selected vianew GridFSDownloadOptions { Seekable = true }) for downloads — are allinternaland not part of the public surface. - File metadata:
GridFSFileInfo<TFileId>(withGridFSFileInfoSerializer<TFileId>). - Options:
GridFSBucketOptions(bucket name,ChunkSizeBytes, read/write concern, read preference);GridFSUploadOptions(ChunkSizeBytesoverride — same property name as the bucket-level default — plus customMetadataandBatchSize(chunks per bulk insert into.chunks));GridFSDownloadOptions(Seekable);GridFSDownloadByNameOptionsextends it withRevision;GridFSFindOptions<TFileId>(with a non-genericGridFSFindOptions : GridFSFindOptions<ObjectId>compat alias for theObjectId-keyed bucket).
Architecture
GridFSBucket holds the cluster reference, an IBsonSerializer<GridFSFileInfo<TFileId>> (_fileInfoSerializer), and a BsonSerializationInfo for the _id field (_idSerializationInfo, which is what enforces the TFileId round-trip discussed in the pitfalls below). Mutating operations (Delete, Rename, OpenUploadStream, Drop) bind via GetSingleServerReadWriteBinding; reads (DownloadAsBytes*, DownloadToStream*, OpenDownloadStream*, Find) bind via GetSingleServerReadBinding. Either way, a single upload/download streams its chunks to the same server (avoids cross-server consistency surprises mid-operation). Note: Find returns an IAsyncCursor, and the single-server property holds for the initial query only — once the cursor's binding is disposed, subsequent getMore calls can be routed independently by the operations layer, so the "same server" guarantee does not extend across the cursor's full lifetime.
Indexes ({filename:1, uploadDate:1} on .files, {files_id:1, n:1} unique on .chunks) are created lazily on the first upload only if the files collection is empty (via an IsFilesCollectionEmpty check). The bool flag _ensureIndexesDone is the actual one-shot guarantor — once set, the short-circuit makes the path a single no-op for the rest of the bucket's lifetime. The accompanying SemaphoreSlim (_ensureIndexesSemaphore) only serializes concurrent first-upload callers so they don't race on the IsFilesCollectionEmpty check; without the bool flag, the semaphore alone would let every caller re-enter the slow path.
Delete can leave orphan chunks if interrupted between its two operations — that is the user-visible hazard, so handle it first. The implementation removes the .files document first (GridFS calls new DeleteRequest(filter) with no explicit Limit; the DeleteRequest constructor's default Limit=1 is what caps the match to a single .files document — there is no Limit = 1 literal in the GridFS code itself), then — after that .files delete returns (whether it matched anything or not) — unconditionally removes any matching chunks. The chunks delete uses an explicit Limit = 0 to remove every matching chunk for the file (the deliberate asymmetry vs. the singular .files delete). There is no try/catch around either call: an exception from the .files delete simply propagates and the chunks delete never runs. After both calls succeed, if the .files deletion matched zero documents, GridFSFileNotFoundException is thrown. The orphan window is any interruption between the two operations — a network error during the chunks delete, but equally a process crash after the .files delete succeeds and before the chunks call is issued. Drop is the only safe full cleanup.
GridFS JSON spec tests run through UnifiedTestSpecRunner.GridFS ([UnifiedTestsTheory("gridfs.tests")]), which picks up everything under specifications/gridfs/tests/ automatically, and the spec's prose tests live in tests/MongoDB.Driver.Tests/Specifications/gridfs/prose-tests/. GridFS coverage also lives in the regular xUnit tests under tests/MongoDB.Driver.Tests/GridFS/, plus the JSON-driven runners pulled in by other specs: tests/MongoDB.Driver.Tests/JsonDrivenTests/JsonDrivenGridFs*.cs and tests/MongoDB.Driver.Tests/UnifiedTestOperations/UnifiedGridFs*Operation.cs exercise GridFS as part of the unified / JSON-driven runners used by transactions, retryable reads/writes, etc.
Common pitfalls
- Unwrapped file IDs in filters. Every driver-built filter carrying a user-provided file id must go through
GridFSIdFilter.Create, which wraps the value in$eq. A serializedTFileIdcan itself be a document, whose keys the server would otherwise read as query operators (CSHARP-6190 / CVE-2026-88025). The spec requires this for_idon.filesandfiles_idon.chunks. - Generic file-ID mismatch. If you pick a custom
TFileId(notObjectId), make sure a serializer is registered. Mismatched serializers silently corrupt the_idfield on.files. - Chunk size vs throughput. The default 255 KiB optimizes for typical web payloads. Very large files with the default size cause many round-trips; bump
ChunkSizeBytes(must stay well below the 16 MiB BSON document limit, since each chunk is a BSON document) for large-file workloads. - Orphaned chunks on interrupted upload.
OpenUploadStreamallocates afiles_id; aborted uploads (exception, cancellation) leave the chunk documents but no metadata. There is no automatic cleanup unless the caller invokesGridFSUploadStream<TFileId>.Abort/AbortAsync(public abstract on the upload stream, implemented byGridFSForwardOnlyUploadStream), which deletes any chunks already written for the in-flightfiles_id. If the upload is interrupted beforeAbortis called — exception caught and swallowed, process crash, unmanaged cancellation — the chunks survive. Log + reconcile, or useDropfor periodic cleanup of test buckets. - Concurrent indexes. First write under load can serialize on the index-creation semaphore. After indexes exist, the cost vanishes — but in fresh test environments expect a one-time delay.
- Revision semantics. The
DownloadAsBytesByName/DownloadToStreamByName/OpenDownloadStreamByNamefamily takes aGridFSDownloadByNameOptionswhoseRevisionproperty defaults to-1(newest, matching the GridFS spec's default-revision semantics), so leaving the property at its default behaves identically to setting it explicitly to-1. Passingoptions: nulllikewise selects newest, since the bucket constructs a defaultGridFSDownloadByNameOptionsinternally.Revision = 0is "oldest". Off-by-one mistakes produce wrong-file failures that look like data corruption — read the spec. Streamownership. Upload/download streams returned by the bucket must be disposed by the caller (using). Disposing closes the cursor and finalizes the upload metadata.
How to test
dotnet test tests/MongoDB.Driver.Tests/MongoDB.Driver.Tests.csproj -f net10.0 \
--filter "FullyQualifiedName~GridFS"GridFS uses a local MongoDB only — no extra environment variables required.
Boundary with operations-reviewer
Chunk-level bulk writes into .chunks, the underlying find cursors over .files / .chunks, and retry semantics for the underlying CRUD operations belong to operations-reviewer (Core/Operations/AGENTS.md). Bucket orchestration — upload/download stream lifecycle, the index-creation bootstrap, Abort semantics, and the two-step Delete ordering described above — belongs here.
Spec links
- GridFS spec:
https://github.com/mongodb/specifications/tree/master/source/gridfs
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

