Skip to content

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 ​

vue
<template>
  <MongocampCollectionInfos collection-name="myCollection" />
</template>

Props ​

PropTypeDefaultDescription
collectionNamestring—Required. Collection to inspect.
sampleSizenumber500Number of documents sampled from the collection to infer the schema.

Stat cards ​

Documents, Data Size, Storage Size, Avg Doc Size, Indexes, Index Size — from collectionApi.getCollectionInformation().

Indexes card ​

Backed by useMongocampIndex, not just getCollectionInformation()'s indexSizes map — each row is a real MongoIndex (name, keys, unique/text/expire flags), with size in KB merged in by name.

  • Create Index opens a form (field name, sort direction, index type — standard / unique / text / expiring, with an "expire after" duration field used only for the expiring type) and calls the matching useMongocampIndex creator.
  • Every row except the default _id_ index (which MongoDB won't let you drop) gets a delete button, behind a confirmation modal.
  • Type flags render as badges using the app's semantic color tokens: unique → warning, text → info, expire → secondary. An index with none of these flags shows a neutral standard badge, so the Type column is never blank.

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:

ts
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:

ColumnMeaning
Fieldthe 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)
Typethe kinds of value found — string, number, boolean, date (an ISO string), object, array, null; when a field holds several, each badge carries its share
Presentin what percentage of the sampled documents the field occurs (the counts in a tooltip); null counts as present
Common valuesthe 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. The server's own schema-analysis endpoint (getSchemaAnalysis) is deliberately not used: on MongoCamp 1.5.10 it returns an accumulation of every analysis made since the server started — fields of other collections included — and its answer grows with every call. The card also drops its result when collectionName changes.

Released under the MIT License.