Skip to content

Core Schema

Every document stored in the Wenex Platform MongoDB carries a fixed set of base fields in addition to its domain-specific payload. These fields are injected or enforced by the Platform and are never set directly by the client at read time.

Identity & Access Fields

FieldTypeRequiredSet byDescription
idstring (MongoId)PlatformUnique document identifier (alias of _id)
refstringClientOptional external reference; unique within collection when used
ownerstring (MongoId)Platform (auto)The user, app, or client that created the document
sharesstring[] (MongoIds)ClientExplicit user-level sharing list
groupsstring[] (FQDN / app ID)Platform (auto) + ClientGroup-level access values; auto-populated from token aid and domain
clientsstring[] (MongoIds)Platform (auto) + ClientClient IDs with access; auto-populated from token cid and coworkers

Lifecycle Timestamps & Actors

Every lifecycle transition records both when it happened and who/where it was triggered. The _by fields are MongoIds referencing identity/users and the _in fields reference domain/apps or domain/clients.

FieldTypeRequiredDescription
created_atDateTimestamp of initial creation
created_bystring (MongoId)User/app/client that created the document (uid ?? aid ?? cid)
created_instring (MongoId)App or client context at creation time (aid ?? cid)
updated_atDateTimestamp of last update
updated_bystring (MongoId)User/app/client that last updated the document
updated_instring (MongoId)App or client context at last update time
deleted_atDate | nullSet on soft-delete; absent when the document is active
deleted_bystring (MongoId)User/app/client that soft-deleted the document
deleted_instring (MongoId)App or client context at soft-delete time
restored_atDateSet on restore; absent when not yet restored
restored_bystring (MongoId)User/app/client that restored the document
restored_instring (MongoId)App or client context at restore time

Metadata & Relations Fields

FieldTypeRequiredDescription
identitystring (MongoId)Polymorphic single-relation field; target collection varies by context
relationsstring[] (MongoIds)Polymorphic multi-relation field; target collection varies by context
descriptionstringShort searchable text summary; indexed for text search
versionstring (SemVer)Document version string (default "1.0.0"), incremented by the client on meaningful changes
propsobjectFree-form JSON schema extension; size-limited
tagsstring[]Searchable tag list
randstring (number-string)Platform-managed random helper value
timestampstring (number-string)Platform-managed numeric timestamp string

Note on polymorphic fields: identity and relations hold MongoIds that may point to any Platform collection. The target collection is determined by application context, not by the schema. Do not assume a fixed target.

Ownership Injection

When a document is created, the OwnershipInterceptor automatically derives and sets ownership fields from the JWT token — the client does not supply them:

FieldDerived from token
owneruid ?? aid ?? cid — user ID if present, otherwise app ID, otherwise client ID
groupsDeduplicated [aid, domain] — app ID (if present) plus the token's domain
clientsDeduplicated [cid, ...coworkers] — token client ID plus all coworker client IDs
created_byuid ?? aid ?? cid
created_inaid ?? cid

When a document is updated, the interceptor sets updated_by and updated_in using the same token-derived logic. It does not touch owner, groups, or clients unless the client explicitly includes them in the request body and the ABAC grant allows it.

A client may pass additional client_id values in clients[] at creation time to grant immediate read access to other applications; the interceptor merges them with the auto-injected coworker IDs.

Soft Delete vs. Hard Delete

All collections use soft-delete by default. The deleted_at field controls document visibility:

Statedeleted_at valueVisible in queries
Activeabsent / nullYes
Soft-deletedISO timestampNo (filtered out by default)
Hard-deletedDocument removed from MongoDB

Use x-exclude-soft-delete-query: true on read requests to include soft-deleted records.

Five lifecycle operations control document state:

OperationHTTPEffect
deleteOne / deleteByIdDELETE /:idSets deleted_at, deleted_by, deleted_in
restoreOne / restoreByIdPUT /:id/restoreClears deleted_at; sets restored_at, restored_by, restored_in
destroyOne / destroyByIdDELETE /:id/destroyPermanently removes the document

Hard delete (destroy) requires the Manage scope. Restore requires Write scope.

The owner, shares, groups, and clients fields drive the ABAC zone filter on every read. See ABAC for how the Platform uses them.