Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsCommunityBlog
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

Back to skills

Mongo

ASecurity

How to use @owlmeans/mongo — MongoDB connection service (makeMongoDbService / appendMongo) registered on a server context; cluster setup, field encryption backend. Auto-invoked when wiring MongoDB into a server app.

3 stars
0 votes
0 copies
0 views
Added 9/22/2026
databasestypescriptgoshellbashnodetestingdatabasebackend

Works with

cli

Security Analysis

A100/100

Scanned 9/22/2026

Install to Claude Code

$npx -y skills add owlmeans/common --skill mongo --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Mongo?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Mongo
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/owlmeans-mongo/badge)](https://www.skillsdirectory.com/skills/owlmeans-mongo)

More formats (shields.io, HTML) on the badges page.

Download Zip
Files
SKILL.md
---
name: mongo
description: How to use @owlmeans/mongo — MongoDB connection service (makeMongoDbService / appendMongo) registered on a server context; cluster setup, field encryption backend. Auto-invoked when wiring MongoDB into a server app.
user-invocable: false
---

# @owlmeans/mongo

**Layer:** Infra
**Install:** `"@owlmeans/mongo": "^0.1.18-rc.28"` in `dependencies`

## Key Exports

| Export | Description |
|--------|-------------|
| `makeMongoDbService(alias?)` | Factory for the MongoDB connection service (implements `MongoDbService` from [[mongo-resource]]). |
| `appendMongo(context, alias?)` | Register the service on a server context. Default alias `'mongo'` (`DEFAULT_ALIAS`). |
| `DEFAULT_ALIAS`, `DEF_REPLSET` | `'mongo'`; `'rs-main'`, the replica set an array `host` bootstraps. |
| `MongoMeta` | The `DbConfig.meta` shape this package reads — `{ replicaSet }`. |

## Usage

```typescript
import { appendMongo } from '@owlmeans/mongo'
appendMongo(context)

// Connection settings come from cfg.dbs
cfg.dbs = [{
  service: 'mongo',
  alias: 'mongo',
  host: '127.0.0.1',        // or string[] for a cluster — triggers replica set setup
  port: 27017,
  user: 'admin', secret: '...',
  schema: 'my-app',          // the DATABASE name
  encryptionKey: '...',      // enables lock()/unlock() field encryption
  meta: { replicaSet: 'rs-main' },   // only read for an array host
}]
```

- The service lazily creates one `MongoClient` per config alias. An array `host` bootstraps the
  replica set first — `replSetInitiate` when the set was never configured, a forced
  `replSetReconfig` when the members' addresses moved, up to three attempts — then reconnects
  through `?replicaSet=<meta.replicaSet ?? DEF_REPLSET>`.
- `lock`/`unlock` encrypt/decrypt record fields with `encryptionKey` via
  `@owlmeans/basic-keys` — the backend behind `MongoResource.lock()`.
- **`user` decides how the connection string is assembled.** With `user` set, a single `host`
  becomes `mongodb://<host>[:<port>]` and the client gets `directConnection: true`, which is what a
  standalone node needs: advertising a replica set instead would block the driver on server
  selection looking for a primary that never appears. `meta.replicaSet` is read only on the
  multi-host path.
- **An entry with no `user` is passed through verbatim.** No scheme is prepended, `port` is not
  appended and no client options are set at all — so such an entry must spell the whole connection
  string in `host` (`mongodb://127.0.0.1:27017/?directConnection=true`). A bare `127.0.0.1` reaches
  the driver as-is and is rejected for having no scheme.
- The database name is `config.schema ?? config.alias ?? service.alias`, taken as given — the
  service's `name(alias?)` returns it. One database per config entry, each carrying its own data
  **and its own migration ledger**; a second database is a second `cfg.dbs` entry.

## Tests

This package hosts the integration suites for the whole Mongo pair (a devDependency in the
other direction would be a cycle): `tests/crud.spec.ts` (the `Resource` contract against a real
collection), `tests/migration.spec.ts` (ledger end to end), `tests/references.spec.ts` (ObjectId
reference conversion, system `$ref:` migration, drift repair). Gated on `MONGO_URL` — see
[[testing-integration]]; a dev port-forward to the cluster mongo fills the `MONGO_URL` the
repo's `.env.example` describes.

## Depends On

- `@owlmeans/resource` (`createDbService`) · `@owlmeans/mongo-resource` (service contract)
- `@owlmeans/context` · `@owlmeans/server-context` — the service lifecycle and the context it asserts
- `@owlmeans/basic-keys` — field encryption
- `mongodb` (`^7.5.0`) — a direct dependency, not a peer: the driver is resolved here and the
  resource package takes it as a peer

## Runtime floor

On Bun, loading this package requires **Bun 1.4.0 or newer**, and that floor is the whole
requirement — `bson` then resolves freely inside the driver's own `^7.2.0` range and needs no
override or pin. `bson@7.3.x` runs a static initializer that calls
`process.getBuiltinModule('v8').startupSnapshot.isBuildingSnapshot()`, which Bun implements from
1.4.0 on. Below that, `import 'mongodb'` throws `NotImplementedError: node:v8 isBuildingSnapshot is
not yet implemented in Bun` before any application code runs, so the symptom is a process that
never starts rather than a query that misbehaves. Every runtime that loads the driver counts: the
local shell, CI, and the container image.

An app that cannot raise its runtime pins the older bson in its own root manifest instead:

```json
{ "overrides": { "bson": "7.2.0" } }
```

Check the runtime, not the lockfile, before lowering one:

```bash
bun -e "import('mongodb').then(() => console.log('OK')).catch(e => console.log(e.message))"
```

## Related

- [[mongo-resource]] — the resource implementation resolved through this service

Attribution

owlmeansowlmeans
View sourceMore from owlmeans →
SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Ship a skill? Prove it's safe.

Free 120-pattern security scan, letter grade, and an embeddable README badge.

Submit a skill

Related Skills

Mysql Best Practices

MySQL development best practices for schema design, query optimization, and database administration

2481 votes

Jpa Patterns

Spring Boot中的JPA/Hibernate实体设计、关系、查询优化、事务、审计、索引、分页和连接池模式。

2456590 votes

Clickhouse Io

ClickHouse数据库模式、查询优化、分析和数据工程最佳实践,适用于高性能分析工作负载。

2456590 votes

Postgres Patterns

基于Supabase最佳实践的PostgreSQL数据库模式,用于查询优化、架构设计、索引和安全。

2456590 votes

Postgresql

Design a PostgreSQL-specific schema. Covers best-practices, data types, indexing, constraints, performance patterns, and advanced features

458250 votes
View all in databases →