useMongocampHistory
The audit records of a declared collection with audit (server 2.3), newest first and paged, as display rows. See Declared collections.
const { documentHistory, collectionHistory } = useMongocampHistory()
const { rows, total, audited } = await documentHistory('orders', id, { page: 1, rowsPerPage: 20, signal })
const recent = await collectionHistory('orders', { since: '2026-11-01T00:00:00.000Z', operation: 'restore' })| Function | Description |
|---|---|
documentHistory(collection, documentId, { page, rowsPerPage, signal }) | GET …/documents/{id}/history — read grant (a deleted document: administrators only) |
collectionHistory(collection, { since, operation, page, rowsPerPage, signal }) | GET /mongodb/collections/{name}/history — administrate grant; a 403 rejects |
restoreVersion(collection, documentId, auditId, state = 'after') | Server 2.11 POST …/documents/{id}/history/{auditId}/restore — puts the content back to the state after (or before) the record: a replace through validation, behaviours and access rules (a versioned document gets a new version; on a drafts collection a published document's working copy), or an insert when the document was deleted. The draft state itself is not restored. Write grant; rejects on failure (404 unknown record, 403 a rule) |
Server 2.11 also adds restoredFrom to a restore record (HistoryRow.restoredFrom, the source record's id) and the operations publish, unpublish, discardDraft.
Both resolve with { rows: HistoryRow[], total, audited }: total from x-pagination-count-rows, audited: false (and no rows) for the server's 404 — a collection without audit, or a deleted document the user may not see. An unknown document id is simply no records. Defaults: page 1, 20 rows, 15 s timeout; signal aborts.
The body is read from the response text, so integers beyond 2^53 in before/after stay exact ({ $numberLong }). HistoryRow (utils/auditEntry.ts, toHistoryRow): id, operation (insert, replace, update, delete, softDelete, restore, or other), user, at (Date | null), documentId?, before?, after?, summary? (a many-write). changedPaths(row) lists what a record changed.