Skip to content

Server Overview ​

@sfxcode/mongocamp-server-core is the MongoCamp REST API as a single web-standard handler:

ts
import { createMongocampServer } from '@sfxcode/mongocamp-server-core'

const server = await createMongocampServer({
  connectionUri: 'mongodb://localhost:27017', // or the CONNECTION_* settings
  config: { CONNECTION_DATABASE: 'mongocamp' }, // any setting by key, env variables win
})

const response = await server.fetch(new Request('http://localhost/version'))
// optional per request: { log } adds the fields of the server to a wide event (evlog), { requestId } sets x-request-id
await server.close()

It does not depend on a framework, so any runtime that speaks Request/Response can host it. In Nitro, connectHooks(server, nitroApp.hooks) makes its events mongocamp:* hooks for the Nitro plugins of the application. This repository hosts it in two ways:

HostHow
Nuxt moduleserver.enabled: true mounts it under server.prefix in your app's Nitro. See Getting Started.
Standaloneapps/server, Nitro 3 without Nuxt, as a Docker image. See Standalone & Docker.

Options of createMongocampServer ​

OptionDescription
connectionUriMongoDB connection string. Without it the CONNECTION_* settings build one.
configSettings by key (Configuration). Environment variables win.
envThe environment to read settings from (default process.env).
version{ name, version } reported by /version, the server header and the served spec. /version adds the core's own version as core (2.8).
onEvent listeners that must already be registered at startup (e.g. server:started).
logger{ info, warn, error } for the messages of the server (default console). See Request Logging & Metrics.
jobsfalse, or { enabled, handlers, refresh }: see Jobs. Handlers can also be added later with server.registerJobHandler().
shutdownCalled by DELETE /system. Without it the route answers 400.
configRefreshHow often (ms) persistent settings are re-read from the database, or false.

What the server provides ​

  • Auth: login, token refresh, API keys, Basic auth, users and roles (/auth/*, /admin/*)
  • Databases and collections: list, info, create with options, rename, copy, clear, drop (/mongodb/databases, /mongodb/collections)
  • Documents: list with Lucene filters, find with MongoDB filters, CRUD, many-insert/update/delete, count, distinct, aggregate, import, export
  • Indexes: list, details, usage statistics, create (ordered keys, text, unique, expiring), drop
  • Files: GridFS buckets and files with metadata
  • System: settings, configurations, jobs, version, info, stats, capabilities, monitoring
  • Docs: the OpenAPI spec at /docs/docs.yaml (DOCS_OPENAPI) and a Scalar API reference at /docs (DOCS_SWAGGER)

The full list is in the REST API reference. Behaviour that the types do not show is described in the API Behaviour pages in the sidebar.

Supported MongoDB versions ​

MongoDB 6.0 and later. CI runs the integration and contract tests against MongoDB 7.

Released under the MIT License.