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, and an inferred schema table with a "Copy as TS Interface" action.

Usage

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

Props

PropTypeDefaultDescription
collectionNamestringRequired. 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: uniquewarning, textinfo, expiresecondary.

Schema card

The schema is not fetched 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.

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
}

Released under the MIT License.