Migrating to 3.0
3.2
3.2 changes one default: field names that start with $ (any depth) or contain . at the top level are refused with 400 (code 4010, the paths in issues). An application that stores such names sets DOCUMENTS_CHECK_FIELD_NAMES=false, or checkFieldNames: false in the declaration of that collection. Stored documents are not touched. See field names.
3.0 changes only a few defaults and removes only names that 2.x already deprecated. Each change has a one-line way back, and the upgrade deletes or rewrites no data: a database written by 2.11 starts with 3.0 as it is. Everything new in 3.0 is opt-in — see what 3.0 adds.
Upgrade in five steps
- Update
@sfxcode/nuxt-mongocamp-server(and@sfxcode/mongocamp-server-core/@sfxcode/mongocamp-clientif you use them directly) to 3.0. - Start once and read the log. The start names declared collections that hold documents their schema refuses (
validation: 'error'is the default now); setvalidation: 'warn'on those you cannot clean up yet. - Search your code for the removed names: server-side
useMongocampApi(event)→useMongocampEventApi(event),gnerateNewApiKeyForUser→generateNewApiKeyForUser,featureSwitches,/system/monitoring/jvm→/system/monitoring/runtime,LOGGING_METRICS_MONGODB_JVM→LOGGING_METRICS_MONGODB_RUNTIME; rename declaration files that start with_. An embedded server that relied onREQUESTLOGGING_ENABLED/METRICS_ENABLEDsets the module optionsrequestLogging/metricsinstead. - Check roles with a
*grant: they no longer reachmc_users,mc_roles,mc_configuration,mc_audit, the backups bucket and the.files/.chunkscollections of buckets. Add a grant that names the collection where a non-admin role really needs it. - Run your tests. Requests that read hidden fields through expressions, or
copy/cleara collection a user sees only partly, now answer403(below).
The 2.x way back of each change is in the last column of the table.
Breaking changes
| Change | Before (2.x) | After (3.0) | Way back |
|---|---|---|---|
USERS_READ_HIDE_API_KEY | false: document reads of mc_users answer apiKey | true: left out like password (the admin user routes keep it) | USERS_READ_HIDE_API_KEY=false |
validation of a declaration | 'warn': invalid documents are stored and logged | 'error': refused with 400, and the MongoDB validator refuses them from other clients; the start warns about stored invalid documents | validation: 'warn' in the declaration |
_id in declared types | only when the schema declared it (_id: z.instanceof(ObjectId).optional()) | InferDocument always has _id: ObjectId, inputs an optional one; a declared _id wins (types only) | keep the line in the schema; it still works |
server useMongocampApi(event) | deprecated name of useMongocampEventApi(event) (since 2.8) | removed (in server code it matched the browser useMongocampApi()) | useMongocampEventApi(event) |
_-prefixed files in server/mongocamp/ | scanned as declarations | ignored, so helpers (_shared.ts) can live next to the declarations | rename the file without _ |
JobInformation (generated client) | description, lastScheduledFireTime, nextScheduledFireTime, scheduleInformation optional, while the API answered null | required and nullable (string | null, Date | null); the answers are unchanged (types only) | check for null instead of undefined |
Whole numbers in collections with validation: 'error' | stored as Int32 (the answer of the schema was written) | stored as sent: Int64 for a plain whole number or $numberLong, Int32 for $numberInt, as in undeclared collections and with 'warn'; defaults of the schema stay Int32 | send { "$numberInt": "3" } for an Int32 |
gnerateNewApiKeyForUser | deprecated alias of generateNewApiKeyForUser (since 2.6) | removed | call generateNewApiKeyForUser |
RATE_LIMIT_LOGIN | empty: failed logins are not limited | 10/15m: after 10 failed logins of a user from one address in 15 minutes the next attempt answers 429 with Retry-After; a successful login resets the count. Behind a proxy set RATE_LIMIT_TRUSTED_PROXIES, otherwise all clients count as the proxy's address | RATE_LIMIT_LOGIN= (empty) |
featureSwitches of createMongocampServer | an embedded server switched request logging and metrics on from REQUESTLOGGING_ENABLED / METRICS_ENABLED with a warning (deprecated since 2.1) | removed: the core reads neither setting; the standalone server still does | Nuxt module options requestLogging / metrics, or server.use(requestLogging()) / server.use(metrics()) |
GET /system/monitoring/jvm | deprecated alias of /system/monitoring/runtime (since 2.1) | removed (404) | /system/monitoring/runtime |
LOGGING_METRICS_MONGODB_JVM | deprecated alias of LOGGING_METRICS_MONGODB_RUNTIME (since 2.1) | removed; a stored value is ignored | LOGGING_METRICS_MONGODB_RUNTIME=true |
* grants | matched every collection and bucket | do not match the server's own collections and buckets (AUTH_PREFIX names such as mc_users, mc_backups, system.*, .files / .chunks, .variants) | a grant that names the collection, or an administrator role |
Security fixes that can refuse requests that 2.x answered
The security review for 3.0 closed ways around scopes and field rules. Requests that used them now answer 403 or 400:
- expressions that read a hidden field:
'$$ROOT','$$ROOT.salary',$getFieldin projections and filters; filters ofupdateMany/deleteManyon hidden fields; distincton anything but a field path (distinct/$ROOT);$graphLookupinto a collection with a read scope or hidden fields ($lookupand$unionWithnow read their collection with its scope and without its hidden fields);copyandclearof a collection the caller sees only partly (scopes, rules,owner,tenant,softDelete,drafts) needadministrate;- dropping, clearing or revoking all links of a declared bucket with
owneroraccessneeds theadministrateright of the bucket; its.files/.chunkscollections are closed to the document routes (except for administrators); qwhen asearchfield is hidden for the caller.
RATE_LIMIT_REQUESTS counts by verified user, and requests without valid credentials count for their address (before, any credential header chose the counter, so random keys escaped the limit). Failed logins are counted before the password check.
Configuration stored by 2.x
A value that an earlier version stored as its default, and that nobody changed (no changedAt), now follows the current default. GET /system/configurations shows it as source: 'default'. The stored document stays as it is, so going back to 2.x finds it unchanged. A value an administrator set (patched) stays as set.
New names (non-breaking)
| Old | New | Note |
|---|---|---|
useMongocampApiCollection(name).update(id, doc) | .replace(id, doc) | update stays and still replaces (the typed useMongocampCollection().update sets fields) |
useMongocampApiCollection(name).updatePartial(id, changes) | .patch(id, changes) | updatePartial stays |
@sfxcode/mongocamp-client errors (MongocampClientError, an Error with the answer's fields) | MongocampRequestError | same fields; also a ResponseError, and current of a version conflict is decoded (ObjectId, Date) |
ResponseError / MongocampRequestError | MongocampRequestError from every call | a subclass of ResponseError, old catch code keeps working; isMongocampError(e) |
Error codes added in 3.0
| Code | Status | |
|---|---|---|
4013 | 401 | the user is disabled |
4014 | 401 | a refresh token used a second time; its session is revoked |
4035 | 403 | login with an unverified e-mail address (AUTH_REQUIRE_VERIFIED_EMAIL) |
4093 | 409 | another user has this e-mail address |
4403 | 400 | a used, expired or unknown link of an auth flow |
5031 | 503 | image variants are busy |
New in 3.0
All opt-in; an application that switches nothing on works as before.
- Auth — optional user fields (
email,displayName,disabled, ...), sessions with rotating refresh tokens, registration, verification, password reset, login by link or code, and the client side inuseMongocampAuth()and the standalone client. - Events — a job queue with retries and dead letters, webhooks of document events (signed, retried, SSRF-guarded), and an outbox so the events of a transaction are never lost.
- AI — embeddings kept in sync through the queue, and an MCP endpoint for AI clients with the rights of a user.
- Data and DX — hooks in the declaration typed by the schema,
MongocampDocument<'orders'>/MongocampExpanded<'orders', 'customerId'>, one error type for every call, long Lucene filters in request bodies ($lucene), an_idprefix as an index range, opt-in response compression, faster large reads.
