Skip to content

useMongocampSystem ​

Read-only wrapper for databaseApi and applicationApi. Powers MongocampDatabases and MongocampSettings.

ts
const {
  listDatabases,             // () => Promise<string[]>
  getDatabaseInfos,          // () => Promise<DatabaseInfo[]>
  getDatabaseInfo,           // (databaseName: string) => Promise<DatabaseInfo>
  listCollectionsByDatabase, // (databaseName: string) => Promise<string[]>
  getCluster,                // () => Promise<{ coordinator, members }>
  getStats,                  // () => Promise<SystemStats>  — uptime, connections, opcounters, replicaSet; `partial` without clusterMonitor; administrators only
  getCapabilities,           // () => Promise<Capabilities> — features, mongoDbMajor, limits, refused aggregation stages; every logged-in user
  getHealth,                 // (kind = 'ready' | 'live') => Promise<{ ok, checks[{ name, ok, message? }] }> — server 2.11, no login; a 503 is an answer (ok false), only no answer rejects
  getServerInfo,             // () => Promise<{ mongoDbVersion, mongoDbVersionArray }>  — MongoDB server version; administrators only (others: `getCapabilities().mongoDbMajor`)
  listConfigurations,        // () => Promise<ConfigRow[]>   — sorted by key, secrets already masked
  getConfig,                 // (configurationKey: string) => Promise<ConfigRow>  — masked
} = useMongocampSystem()

Read-only, and secrets never leave it ​

databaseApi.deleteDatabase, applicationApi.shutdown and applicationApi.updateConfiguration are not wrapped here — they are cross-cutting and highly destructive, and the composable does not expose a write path of any kind. If you need one, call useMongocampApi() directly rather than extending this composable, which keeps the "read-only" contract honest for anything that relies on it.

The server's settings and configuration payloads contain real secrets (the auth secret, database credentials and host), so the settings methods never hand them out:

  • getCluster() returns the server's cluster view (systemApi.viewCluster, 15 s timeout): the coordinator and the members (name, coordinator, siteMaster, …). members is optional in the API type; when absent or empty it falls back to [coordinator]. On a single node there is one member whose name is an opaque container id plus port.
  • There is no getSettings() any more: since server 2.2 GET /system/settings holds only the configuration map, secrets included, so the composable never calls it (the plugin lists it used to return are gone with the server's plugin model).
  • listConfigurations() and getConfig(key) return ConfigRows — { key, value, masked, configType, needsRestart, comment, source?, isDefault?, defaultValue? } (the last three since server 2.8; defaultValue formatted and masked like value) — in which a secret's value is already "••••••••" and the original was never copied. See MongocampSettings for the masking rule. getConfig throws if the server answers with something that is not a configuration.

Values are normalised on the way in: the generated client types a configuration's value as a number, but real values are numbers, booleans, strings, lists, null and Option values wrapped as { value }.

getDatabaseInfos vs listDatabases ​

getDatabaseInfos() returns full DatabaseInfo objects (name, sizeOnDisk, empty, fetched, map) for every database in one call — use this for a listing table. listDatabases() returns just the name strings; getDatabaseInfo(databaseName) fetches detail for one database at a time. Prefer getDatabaseInfos() over listDatabases() + N getDatabaseInfo() calls to avoid an N+1 request pattern.

Every call has a 15s timeout ​

The generated API client has no built-in request timeout — a hung server response otherwise leaves the caller's promise pending forever (neither resolved nor rejected), which no amount of try/catch in the calling component can recover from. Every method here passes an AbortSignal.timeout(15000) via initOverrides, so a dead or slow endpoint always surfaces as a rejected promise within 15 seconds instead of hanging the page indefinitely.

Released under the MIT License.