Skip to content

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 ​

  1. Update @sfxcode/nuxt-mongocamp-server (and @sfxcode/mongocamp-server-core / @sfxcode/mongocamp-client if you use them directly) to 3.0.
  2. Start once and read the log. The start names declared collections that hold documents their schema refuses (validation: 'error' is the default now); set validation: 'warn' on those you cannot clean up yet.
  3. 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 on REQUESTLOGGING_ENABLED / METRICS_ENABLED sets the module options requestLogging / metrics instead.
  4. Check roles with a * grant: they no longer reach mc_users, mc_roles, mc_configuration, mc_audit, the backups bucket and the .files / .chunks collections of buckets. Add a grant that names the collection where a non-admin role really needs it.
  5. Run your tests. Requests that read hidden fields through expressions, or copy / clear a collection a user sees only partly, now answer 403 (below).

The 2.x way back of each change is in the last column of the table.

Breaking changes ​

ChangeBefore (2.x)After (3.0)Way back
USERS_READ_HIDE_API_KEYfalse: document reads of mc_users answer apiKeytrue: 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 documentsvalidation: 'warn' in the declaration
_id in declared typesonly 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 declarationsignored, so helpers (_shared.ts) can live next to the declarationsrename the file without _
JobInformation (generated client)description, lastScheduledFireTime, nextScheduledFireTime, scheduleInformation optional, while the API answered nullrequired 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 Int32send { "$numberInt": "3" } for an Int32
gnerateNewApiKeyForUserdeprecated alias of generateNewApiKeyForUser (since 2.6)removedcall generateNewApiKeyForUser
RATE_LIMIT_LOGINempty: failed logins are not limited10/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 addressRATE_LIMIT_LOGIN= (empty)
featureSwitches of createMongocampServeran 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 doesNuxt module options requestLogging / metrics, or server.use(requestLogging()) / server.use(metrics())
GET /system/monitoring/jvmdeprecated alias of /system/monitoring/runtime (since 2.1)removed (404)/system/monitoring/runtime
LOGGING_METRICS_MONGODB_JVMdeprecated alias of LOGGING_METRICS_MONGODB_RUNTIME (since 2.1)removed; a stored value is ignoredLOGGING_METRICS_MONGODB_RUNTIME=true
* grantsmatched every collection and bucketdo 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', $getField in projections and filters; filters of updateMany / deleteMany on hidden fields;
  • distinct on anything but a field path (distinct/$ROOT);
  • $graphLookup into a collection with a read scope or hidden fields ($lookup and $unionWith now read their collection with its scope and without its hidden fields);
  • copy and clear of a collection the caller sees only partly (scopes, rules, owner, tenant, softDelete, drafts) need administrate;
  • dropping, clearing or revoking all links of a declared bucket with owner or access needs the administrate right of the bucket; its .files / .chunks collections are closed to the document routes (except for administrators);
  • q when a search field 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) ​

OldNewNote
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)MongocampRequestErrorsame fields; also a ResponseError, and current of a version conflict is decoded (ObjectId, Date)
ResponseError / MongocampRequestErrorMongocampRequestError from every calla subclass of ResponseError, old catch code keeps working; isMongocampError(e)

Error codes added in 3.0 ​

CodeStatus
4013401the user is disabled
4014401a refresh token used a second time; its session is revoked
4035403login with an unverified e-mail address (AUTH_REQUIRE_VERIFIED_EMAIL)
4093409another user has this e-mail address
4403400a used, expired or unknown link of an auth flow
5031503image variants are busy

New in 3.0 ​

All opt-in; an application that switches nothing on works as before.

Released under the MIT License.