Skip to content

MongocampCollections ​

Table of all collections in the default database, with document count, storage size, and index count. Each row links to the collection's info and data pages. Includes a client-side filter input and sortable column headers.

Usage ​

vue
<template>
  <MongocampCollections
    info-path="/secured/admin/collections"
    data-path="/secured/admin/collections"
    bucket-files-path="/secured/admin/buckets"
  />
</template>

Props ​

PropTypeDefaultDescription
infoPathstring/secured/admin/collectionsBase path for the info-page link: <infoPath>/<name>
dataPathstring/secured/admin/collectionsBase path for the data-page link: <dataPath>/<name>/data
bucketFilesPathstring/secured/admin/bucketsBase path for the bucket file-browser link (bucket rows only): <bucketFilesPath>/<bucketName> — points at a consumer-owned page rendering MongocampBucketFiles
canManagebooleantrueSet to false to hide Clear and Drop for ordinary collections even for an admin
hideHeadingbooleanfalseHide the component's own heading, e.g. when the page around it already shows a title. The toolbar stays.
hideRefreshbooleanfalseHide the component's own reload button, e.g. when the page calls the exposed refresh() from its own header.

In a page with its own header ​

The component can hand its toolbar to the page around it:

  • refresh() is exposed — call it through a template ref from your own reload button, and set hideRefresh to drop the built-in one.
  • toolbar slot — your own buttons, placed beside the built-in ones.
  • changed event — see Events.
vue
<script setup lang="ts">
const list = useTemplateRef<{ refresh: () => void }>('list')
</script>

<template>
  <header>
    <h1>My title</h1>
    <UButton icon="i-lucide-refresh-cw" @click="list?.refresh()" />
  </header>
  <MongocampCollections ref="list" hide-heading hide-refresh @changed="reloadOtherLists">
    <template #toolbar>
      <UButton>Mine</UButton>
    </template>
  </MongocampCollections>
</template>

Events ​

EventDescription
changedA collection or bucket was cleared or dropped/deleted and the list has been refreshed

Columns ​

ColumnDescription
CollectionName, sortable — GridFS bucket collections (.files/.chunks) show a "bucket" badge
DocumentsDocument count
Size (KB)Storage size
IndexesIndex count
—Info / data action buttons, clear / drop on ordinary collections (admins), bucket actions on bucket-backed rows

Behavior ​

  • Fetched via collectionApi.listCollections() + collectionApi.getCollectionInformation() per collection.
  • Collections whose name starts with mc (MongoCamp's internal collections) are filtered out.
  • The filter input matches client-side against the already-loaded rows.

Chart ​

With two or more collections a collapsed Chart section shows the biggest ten as bars (storage size or document count, switchable; the rest summed as "other"). It is built from the numbers the table already loaded — no extra request — with the data table as a text alternative.

Clear and drop ​

Admins (useMongocampRoles().isAdmin) get two more actions on every ordinary collection:

  • Clear collection — deletes every document, keeps the collection (and its indexes).
  • Drop collection — deletes the collection with all its documents and indexes.

Both sit behind a MongocampConfirmByName modal: nothing happens until the exact collection name is typed, and a refused call (for example 403) keeps the modal open with the reason. On success a toast appears, the list is refetched and changed is emitted. Both are irreversible.

They are never offered for MongoCamp's own mc_* collections or for the .files/.chunks halves of a GridFS bucket — those go through the bucket actions below, which handle both halves. The rule is the pure predicate isProtectedCollection in src/runtime/utils/collectionProtection.ts. Non-admins see neither action, and canManage="false" hides them for everyone.

Server proxy mode

With useServerProxy the browser never logs in, so the isAdmin check above can't protect anything: every visitor of your app can reach these buttons, and the request runs with the api key's full power. Guard the proxy route with the mongocamp-proxy:authorize hook, or hide the actions with canManage="false".

Bucket actions ​

Rows for a .files or .chunks collection (detected via useMongocampBucket's isBucketCollection) get three extra actions:

  • Browse files — links to <bucketFilesPath>/<bucketName>, a consumer-owned page rendering MongocampBucketFiles for that bucket
  • Clear bucket — behind a type-the-bucket-name confirmation (MongocampConfirmByName), deletes every file in the bucket, keeps the bucket itself; refetches the collection list on success
  • Delete bucket — behind the same confirmation, drops both the .files and .chunks collections permanently; refetches the collection list on success

The bucket actions are shown to every user (the server enforces permissions); a failed action keeps the modal open with a message.

The .files/.chunks pair is not collapsed into a single row — each stays independently browsable via MongocampCollectionData; the badge and bucket actions are just added to both rows.

Copy and backup ​

Administrators get a Copy collection button on ordinary collections (never mc_* or GridFS halves). It opens MongocampCollectionCopy: copy into a named new collection, or a Quick backup into <name>_backup_<date>_<time>. The list reloads when a copy finished. canManage hides it together with clear and drop.

Rename ​

The same people get a Rename collection button: MongocampCollectionRename renames it inside the database (documents and indexes stay) and warns first that grants are by name, so the old name's grants stop applying. The list reloads and changed is emitted.

Released under the MIT License.