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. |
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().
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) 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.
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 and works the same on every server version.
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. It scans about 10 000 documents per second (50 000 took 5.4 s on the dev server) and is therefore refused — the button is disabled with an explanation — for collections of more than 200 000 documents, and for an empty one; a request that outlasts its timeout (15 s plus 0.4 ms per document) says so and offers Retry. Retry repeats whichever analysis failed.
(Notes on the server endpoint: (On MongoCamp up to 1.5.x that endpoint returned an accumulation of every analysis made since the server started — fields of other collections included; it is clean since 1.6.1, re-verified on 1.6.3.) The card also 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.