useMongocampDocument
Helpers for document-level operations.
ts
const {
ensureMetaData, // <T extends { metaData?: Partial<MetaData> }>(data: T) => T
updateFromPartial, // <T>(obj: T, updates: Partial<T>) => T
} = useMongocampDocument()ensureMetaData
Stamps a document with createdBy / updatedBy / created / updated from the currently logged-in user (via useMongocampStorage()):
- If
metaData.createdByis not already set, bothcreatedByandupdatedByare set to the current user, andcreated/updatedare set to now. - If it's already set (i.e. an existing document),
createdByandcreatedare preserved, and onlyupdatedBy/updatedare refreshed.
ts
const { ensureMetaData } = useMongocampDocument()
const stamped = ensureMetaData({ name: 'Acme Corp', metaData: existingDoc.metaData })
await documentApi.insert({ collectionName, requestBody: stamped })updateFromPartial
A plain shallow-merge helper: { ...obj, ...updates }. Useful for building the request body of a partial update without mutating the original object.