> ## Documentation Index
> Fetch the complete documentation index at: https://ayakaleaf-pro.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Project History Sharded Blobs Collection

`projectHistoryShardedBlobs` holds the blob records that did not fit into [projectHistoryBlobs](https://ayakaleaf-pro.mintlify.site/dev/data-model/project-history-blobs-collection.md): when the bucket for a hash prefix already has 8 records there, the next ones go here. A project has at most 16 documents in it, one per first hex digit of the hash. There is no Mongoose schema; history-v1 writes it in `services/history-v1/storage/lib/blob_store/mongo.js` (layout described at `mongo.js:1-16`).

#### Fields

| Field | Type | Meaning | Source |
| - | - | - | - |
| `_id` | Binary | 13 bytes: the history id of the project, a `0`, and the shard digit, read as hex (`<history id>0<digit>`). The shard digit is the first hex digit of the hash. | `mongo.js:439-453` |
| `blobs` | Object | Blob records grouped in buckets. The key of a bucket is hex digits 2 to 4 of the hash. | `mongo.js:439-443` |
| `blobs.<bcd>` | Array of Object | The records of the bucket. The code puts no limit on its size. | `mongo.js:399-407` |
| `blobs.<bcd>[].h` | Binary | The hash, 20 bytes, as in projectHistoryBlobs. | `mongo.js:472` |
| `blobs.<bcd>[].b` | Number | Byte length of the content. | `mongo.js:473` |
| `blobs.<bcd>[].s` | Number | Length of the content as text; `null` when the content is not editable text. | `mongo.js:474` |

#### Who Writes It

| Code | What it does |
| - | - |
| `services/history-v1/storage/lib/blob_store/mongo.js:399-407` | `insertRecordSharded`: upsert with `$addToSet` into the bucket. Called by `insertBlob` when the bucket in projectHistoryBlobs is full (`mongo.js:387-389`). |
| `mongo.js:75-103` | `clone`: copies the project's shards to another history id, for history-v1 `POST /projects/:project_id/clone`, which nothing in web calls. |
| `mongo.js:413-422` | `deleteBlobs`: deletes all shards of the project together with its projectHistoryBlobs document, on history-v1 `DELETE /projects/:project_id`. |

#### Who Reads It

| Code | What it does |
| - | - |
| `mongo.js:144-157` | `findBlobSharded`: one blob, looked up only when its bucket in projectHistoryBlobs has 8 records and does not hold it (`mongo.js:127-131`). |
| `mongo.js:217-260` | `findBlobsSharded`: the blobs `findBlobs` did not find in projectHistoryBlobs (`mongo.js:202-206`). |
| `mongo.js:285-306` | `getProjectBlobs`: all shards of a project. |
| `mongo.js:337-361` | `getProjectBlobsBatch`: all shards of several projects, for the blob stats route. |

#### Indexes

Only the default `_id` index. No migration in `tools/migrations/` adds one.

#### Notes

* The shards of one project sit next to each other in `_id` order, so the code finds them with an `_id` range from `<history id>00` to `<history id>0f` (`mongo.js:75-80`, `287-295`).
* The collection only appears once some project has more than 8 blobs with the same 3-digit hash prefix, so a small instance may not have it at all.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.