Skip to content

Declared collections ​

Since MongoCamp server 2.3 an app can declare a collection in server/mongocamp/<name>.ts with defineMongocampCollection and switch behaviours on, one flag each: timestamps, owner, softDelete, versioned, audit, protectedFields. How to declare them is described in the server's declared-collections guide. This page describes what the module's components do with them.

The components ask the server for the declaration of a collection (GET …/declaration, once per collection and signed-in user — useMongocampDeclaration). An undeclared collection (404) behaves exactly as before; a failed request is treated like "not declared", and a write is never blocked by it.

What each behaviour changes ​

BehaviourIn the module
any declarationMongocampCollectionInfos shows a Declared collection card: validation mode, one row per behaviour, the server-owned fields
system fields (timestamps, owner, the version, the deleted mark) and protectedFieldsthe edit form shows them read-only with a note, an insert leaves them out, a save never sends them as a change, and bulk edit does not offer them. The server ignores them anyway — the form just stops pretending otherwise
timestampsthe module's own metaData stamp is no longer added — the server writes the times. Server 2.7/2.8: preserveOnInsert (an administrator's insert keeps the times and users it sends — imports of exports) and preserveOnUpdate (an administrator's update keeps updatedAt/updatedBy with the header X-MONGOCAMP-KEEP-TIMESTAMPS: true) are named on the card, and the import wizard says whether the file's values are kept (it adds no metaData stamp of its own to such a collection); preservedOnInsert(declaration) in utils/declaration.ts lists those fields. owner.preserveOnInsert works the same, but server 2.8 does not answer it in the declaration yet
versionedan edit sends the version it was based on (a top-level key named by versioned.field, dotted for a nested field). A required collection then accepts the edit instead of answering 428, and an outdated edit opens the conflict dialog instead of overwriting someone else's change
softDeletedelete wording says the document can be restored; administrators of the collection get Show deleted (withDeleted), deleted rows carry a Deleted badge, can only be viewed, and have Restore (write grant)
audita History row action opens MongocampDocumentHistory; the info page has a MongocampCollectionHistory card
ownernothing extra: the server hides other users' documents (404), so the table simply shows what the user may see
indexes (2.4)the card lists them (2.6: with sparse, the behaviour that asked for one, the soft-delete partial filter); MongocampIndexes marks them declared (2.6: for owner …), warns that a dropped one comes back at the next start, and notes that lasting indexes belong in the declaration
refs (2.4)the card links each reference to its target; the data table's References menu expands them on the page read (≤ 5); the edit form picks them by name; lookups both ways (2.6) — see references
file references (2.11, { avatarId: { bucket: 'avatars' } })kept apart from document references (declaration.fileRefs): the card's Files line links the bucket; the cell shows the file (its name when expanded) and opens the file preview; the edit form takes the 24-hex file id; never offered to the reference picker, lookups or bulk edit
search (2.10)the query bar gets a search box (q): best matches first unless sorted, paged by number; while searching, export all, the aggregate link, the chart and select all matching are off (the server ignores q there)
views (2.10)a Views button in the data table runs one (MongocampCollectionView): parameters as a JSON object, refused ones named, table or chart
drafts (2.11)readers see published states only; writers get Drafts (working copies), a status badge (Draft / Published / Unpublished changes) and a Publishing menu (publish, publish changes, discard changes, unpublish); the edit form starts from the working copy
audit + restore (2.11)an opened history record offers Restore this version / Restore the state before (write grant); a restore record links the record it came from. On a drafts collection the restored state waits in the working copy
access (2.10)the card lists the rule per operation (everyone / nobody / roles … / a rule of the server); a refusal is "The access rules of this collection do not allow this." (403, code 4033) — the module does not hide buttons by rule, it shows the server's verdict. A field rule hides fields from rows; a filter on such a field is reported as a rejected filter with Clear filters
tenant (2.10)the card names the field; it is a system field (read-only in the form). Which tenant a user belongs to is decided by the server
embedding (3.0)the card names the source fields, the vector field and its dimensions; the vector and embeddingHash are system fields the server keeps in sync through the queue — with readable: false (the default) reads leave them out, so the table never shows them. No vector search UI

Version conflicts ​

When someone else saved the document between the read and the save, the server answers 409 with the stored document (current — canonical Extended JSON, since the edit writes ask extendedJson=canonical, server 2.8). MongocampVersionConflict then shows the stored document next to what it becomes with the user's changes applied on top, and names the fields both sides changed:

  • Apply my changes sends the user's changes again with the stored version — fields only the other side changed stay as they are; where both changed, the user's value wins. Another conflict in the meantime refreshes the dialog.
  • Discard my changes closes the edit and reloads the table.
  • Keep editing returns to the form.

The merge is computed by utils/versionConflict.ts (rebaseChanges, applyChanges). An edit that the table could not save as a partial update (a top-level key with a dot or $) cannot be merged; it gets the plain "reload and change it again" message.

References ​

With refs declared, the query bar of MongocampCollectionData has a References menu. A ticked reference is sent as expand with the page read only, so the cell shows the referenced document's name / title / label / email (else its id) and opens it in the view drawer — no extra request. An array shows its first three. A reference the user may not read, or that points nowhere, shows not readable (the server answers null; in an array it leaves it out).

Expanding is display only: edits, bulk edits, compare, counts and charts read the documents without it, the edit form's fields come from the rows with references as ids again, and the page export writes ids. The view drawer's Show references reads one document with expand; Export all matching can expand for JSON and NDJSON (CSV cannot — the server answers 400). Such a file is for reading: a re-import would store the documents as they are.

Picking a reference ​

In the edit and insert form a declared reference is a picker over the target: it shows the chosen document by name, searches the target's name / title / label / email (and the start of an id) as you type — at most 20 matches, case-insensitive — and a reference that holds an array (many) picks several. The value stays the id; it is saved as an ObjectId ({ $oid }), on an insert too. A reference the user cannot read keeps its id, marked not readable. Without a read grant on the target the field is the id as text, checked to be 24 hex characters. Bulk edit does not offer references. The picker is built on useMongocampReferenceOptions.

Lookups ​

Server 2.6 filters a declared reference by an id (customerId:<hex>). The module uses it in three places:

  • next to a reference in a cell, the filter button narrows the table to the rows with that document (AND the filter on screen); the referenced document's drawer offers the same and Open in <collection>;
  • the drawer of a row of a referenced collection (customers) lists Referenced by links — orders · customerId opens the orders data page filtered to this customer (only collections the user may read);
  • the declaration card lists Referenced by with links to those collections.

The links open a data page with ?filter=… — the page hands it to MongocampCollectionData as initialFilter (see the data table).

Grants ​

ActionNeeds
see the declarationread grant
Show deleted (withDeleted)administrate grant (the toggle is hidden without it; the server answers 403)
Restorewrite grant
document historyread grant (a deleted document: administrators only)
collection historyadministrate grant (without it the card shows a note)
Drafts (working copies), Publishingwrite grant (and the collection's update rule, or drafts.readers)
restore a versionwrite grant (the access rules apply to the restore too)
run a viewread grant (the server applies the read scope first)
bucket Share link / Revoke all linksread / write grant of the bucket

Declared buckets ​

A bucket declared with defineMongocampBucket (server 2.11, server/mongocamp/buckets/<name>.ts) shows a Declared bucket badge and the collections whose file references point at it (MongocampBucketFiles). A refused upload names the allowed types. The server does not announce the bucket's types or image variants, so the component cannot narrow the file picker; give it the preset names you declared (thumbnailPreset, previewPreset) for thumbnails and smaller previews (sharp must be installed in the app that runs the server, else the column goes away with a note). Signed links work for any bucket.

Not covered ​

Live updates (…/documents/watch, useMongocampLive, also their expand and followRefs), batch writes (POST /batch, useMongocampBatch) and transactions need a replica set for their atomic forms and have no UI in the module. Changing an owner, purging soft-deleted documents and editing declarations (they are code) are not part of the UI either.

Released under the MIT License.