MongocampCollectionInfos
Stat-card grid for a single collection — document count, data size, storage size, avg doc size, index count, and total index size — plus an index management table, an inferred schema table with a "Copy as TS Interface" action, and on-demand field statistics.
Usage
<template>
<MongocampCollectionInfos collection-name="myCollection" />
</template>Props
| Prop | Type | Default | Description |
|---|---|---|---|
collectionName | string | — | Required. Collection to inspect. |
sampleSize | number | 500 | Number of documents sampled from the collection to infer the schema. |
hideDeclaration | boolean | false | Hides the Declared collection card. |
hideHistory | boolean | false | Hides the history card of an audited collection. |
Exposed
refresh() loads the numbers, the schema sample and the index card again — for a page that puts the reload in its own header. The component has no reload button or heading of its own.
Stat cards
Documents, Data Size, Storage Size, Avg Doc Size, Indexes, Index Size — from collectionApi.getCollectionInformation().
A collection that does not exist (any more) answers 404: instead of an empty page the component shows a MongocampErrorAlert titled Could not load plus the collection name, with the server's message and Retry.
Declared collection
For a collection declared on the server (2.3, see Declared collections) a card shows the validation mode (off / warn / error), one row per behaviour that is on — timestamps (the fields; server 2.7/2.8: whether an administrator's insert keeps the values it sends, preserveOnInsert, and an update keeps the change fields when asked, preserveOnUpdate), owner (field and who reads, and whether an administrator's insert keeps the owner it sends), soft delete (field, purge days), versioned (counter field or update time, every change must send it), audit history (days kept) — and the fields the server writes or protects. Server 2.4/2.6: the declared indexes (with unique, sparse, the behaviour that asked for one and the soft-delete partial filter), the references linking their targets, and Referenced by linking the collections whose references point here. Server 2.10/2.11: rows for full-text search (fields with weights, language), tenants (field, whether administrators see every tenant), access rules (per operation: everyone with the grant / nobody / roles … / a rule of the server), drafts (who reads the working copies) and, server 3.0, embeddings (the source fields, the vector field, dimensions, whether reads carry it); Files linking each file reference's bucket, and Views (a view with parameters is marked (…), its description as the tooltip). An undeclared collection (404) shows nothing. An audited collection also gets MongocampCollectionHistory below it.
Indexes card
The card is MongocampIndexes: every index with its keys in order, type flags, size and usage (a never used since … hint), Create Index (standard, unique, text, expiring — compound for standard and unique) and a drop button behind a typed confirmation, never for _id_. After an index was created or dropped the stat cards above are refreshed.
Distribution card
Choose a field (text, true/false, date or number) and MongocampCollectionCharts draws its distribution. Nothing is requested until a field is chosen.
Schema card
The table below is not built from collectionApi.getJsonSchema() — it's inferred client-side by sampling up to sampleSize real documents (documentApi.listDocuments, relaxed Extended JSON so ids, dates and date-looking text keep their types; no count, count=none) and running them through useMongocampSchema().schemaFromSamples(). This means:
- Nested objects and arrays (including arrays of objects) get real inferred shapes, not just a generic "object"/"array" label.
- The Type badge uses the app's semantic color tokens (
neutral/warning/info/success/secondary/primary) per type. - "In all samples" reflects whether the field had a non-null value in every sampled document — not just whether the key was present.
JSON schema
The JSON schema header button opens a modal with the server's own inferred schema (collectionApi.getJsonSchema(), via useMongocampAdmin().getJsonSchema), shown verbatim as formatted JSON — useful because it is more precise than the sampled table (for example objectId and integer, with null as an alternative). Nothing is requested until the modal is first opened; the answer is kept until collectionName changes. Copy puts the JSON on the clipboard, Download saves it as <collection>.schema.json, and a failed load shows the error alert with Retry.
Suggested validator
Suggest validator (server 2.3) opens the same modal with a MongoDB $jsonSchema validator that the server builds from a sample of the documents (collectionApi.getSuggestedValidator(), default 1 000 documents, via useMongocampAdmin().getSuggestedValidator): BSON types per field, nested objects, array items and the fields present in every sampled document as required. Above the JSON it says how many documents it was made of and lists the server's warnings (for example a field with several types). Nothing changes on the server — copy it into the collection's validator or into a declared collection (server/mongocamp/<name>.ts, validator). Requested on first open, kept until collectionName changes; Download saves <collection>.validator.json.
Copy as TS Interface
The header button copies a full TypeScript interface (plus any nested interfaces needed for object/array-of-object fields) to the clipboard, generated by schemaToTsInterface. Example, for a carts collection with an items array of objects and a shippingAddress object:
interface Carts {
id: number
customerId: number
items: CartsItem[]
shippingAddress?: CartsShippingAddress
status: string
tags: string[]
}
interface CartsItem {
productId: number
quantity: number
unitPrice: number
}
interface CartsShippingAddress {
line1: string
city: string
postalCode: number
country: string
}Field statistics card
An Analyze fields button (nothing is requested until it is clicked) with a sample size select (100 / 500 / 1 000). It takes a random sample of that many documents — one $sample aggregation, see useMongocampAggregation — and shows, per field:
| Column | Meaning |
|---|---|
| Field | the path: address.city for a nested field, items[].sku for a field of the objects inside an array (the parent object/array is listed too; nesting is followed three levels deep, at most 200 fields are shown) |
| Type | the kinds of value found — string, number, boolean, date (an ISO string), object, array, null; when a field holds several, each badge carries its share |
| Present | in what percentage of the sampled documents the field occurs (the counts in a tooltip); null counts as present |
| Common values | the most frequent values (up to five, with counts) — only for scalar fields with at most 20 distinct values; ids and names, which say nothing, get none |
The badge in the card header says how many of the collection's documents were sampled, and a note reminds you it is a sample, not the whole collection. A field with many distinct values or large values makes the sample heavier — pick a smaller size for a collection with big documents. Asking again always gives a fresh, equally sized answer.
The statistics are computed in the browser from the sample by default, which needs no extra request.
Analyze all documents
The second button, Analyze all documents, asks the server for its own analysis of every document (getSchemaAnalysis, see useMongocampAdmin) and shows it in the same table: the badge reads "All N documents analyzed" and the note says the server did it. Use it when a sample of a few hundred documents could miss rare fields or skew the shares. Differences to the sample: the numbers are exact, the Common values column is empty (the server lists none), and the share of a field inside array elements (items[].sku) is the share of documents that have it. The server reads tens of thousands of documents per second (100 000 took 1.2 s on a local server); the analysis is refused — the button is disabled with an explanation — for collections of more than 1 000 000 documents, and for an empty one; a request that outlasts its timeout (15 s plus 0.05 ms per document) says so and offers Retry. Retry repeats whichever analysis failed.
The card drops its result when collectionName changes.
After a field analysis, a collapsed Field presence chart under the table shows the share of documents that have each field (the 20 sparsest, ties by name) — from the analysis already computed, no request.
Related composables
useMongocampAggregationuseMongocampSchemauseMongocampIndexuseMongocampAdmin(getJsonSchema,getSuggestedValidator)