npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@foxframework/db-documentdb

v1.0.0

Published

AWS DocumentDB provider for Fox Framework — MongoDB-compatible with TLS and collection auto-creation

Readme

@foxframework/db-documentdb

AWS DocumentDB provider for Fox Framework — MongoDB-compatible with TLS support and automatic collection/index creation on connect.

Wraps @foxframework/db-mongo and adds DocumentDB-specific TLS connection handling via buildDocumentDbUri.

Installation

npm install @foxframework/db-documentdb @foxframework/db-mongo mongodb
npm install --save-dev @types/mongodb

Both @foxframework/db-mongo and mongodb are peer dependencies — you control which versions you use.

Quick start

import { DocumentDbProvider } from '@foxframework/db-documentdb';

const db = new DocumentDbProvider({
  uri: 'mongodb://admin:[email protected]:27017',
  database: 'myapp',
  tls: true,
  tlsCaFile: '/path/to/global-bundle.pem', // AWS DocumentDB CA bundle
  entities: [usersCollection],
});

await db.connect(); // connects + auto-creates collections and indexes

interface User {
  id?: string;
  name: string;
  email: string;
}

const users = db.collection<User>('users');

const alice   = await users.create({ name: 'Alice', email: '[email protected]' });
const found   = await users.findById(alice.id!);
const all     = await users.findAll({ filter: { name: 'Alice' }, limit: 10 });
const updated = await users.update(alice.id!, { name: 'Alice Smith' });
const deleted = await users.delete(alice.id!);
const total   = await users.count({ name: 'Alice' });

await db.disconnect();

Collection auto-creation

Pass entities to have collections and indexes created automatically on connect(). The initializer is idempotent — it checks for the collection before creating it.

import type { CollectionDefinition } from '@foxframework/db-documentdb';

const usersCollection: CollectionDefinition = {
  name: 'users',
  indexes: [
    { name: 'email_unique', fields: { email: 1 }, unique: true },
    { name: 'name_idx',     fields: { name: 1 } },
  ],
};

const db = new DocumentDbProvider({
  uri: 'mongodb://...',
  database: 'myapp',
  tls: true,
  tlsCaFile: '/path/to/global-bundle.pem',
  entities: [usersCollection],
});

await db.connect(); // users collection + indexes are ready

TLS / Connection

buildDocumentDbUri appends the required DocumentDB query params when tls: true:

| Param | Value | |---|---| | tls | true | | retryWrites | false | | readPreference | secondaryPreferred | | tlsCAFile | value of config.tlsCaFile (if provided) |

When tls: false the URI is used as-is (useful for local testing with a real MongoDB instance).

API

DocumentDbProvider

| Method / Property | Description | |---|---| | connect() | Builds the TLS URI, connects via MongoProvider, auto-creates collections | | disconnect() | Closes the connection | | collection<T>(name) | Returns an IMongoRepository<T> for the named collection | | isConnected | true after connect() succeeds |

IMongoRepository<T>

| Method | Description | |---|---| | findById(id) | Find document by string ID (_idid) | | findOne(filter?) | First matching document | | findAll(options?) | All matching documents with filter, sort, limit, skip, projection | | create(data) | Insert a document, returns it with id string | | update(id, data) | Partial update by ID | | delete(id) | Delete by ID, returns boolean | | count(filter?) | Count matching documents |

CollectionInitializer

Low-level helper used internally by DocumentDbProvider. Can be used standalone if you need to manage collections outside of the provider lifecycle.

import { CollectionInitializer } from '@foxframework/db-documentdb';

const initializer = new CollectionInitializer(() => mongoDb);
await initializer.ensureCollections([usersCollection, ordersCollection]);

buildDocumentDbUri(config)

Utility that constructs a TLS-enabled DocumentDB connection string from a DocumentDbConfig.

import { buildDocumentDbUri } from '@foxframework/db-documentdb';

const uri = buildDocumentDbUri({
  uri: 'mongodb://user:pass@host:27017',
  database: 'mydb',
  tls: true,
  tlsCaFile: '/etc/ssl/rds-ca.pem',
});
// → 'mongodb://user:pass@host:27017/?tls=true&retryWrites=false&readPreference=secondaryPreferred&tlsCAFile=%2Fetc%2Fssl%2Frds-ca.pem'

Configuration

interface DocumentDbConfig {
  uri: string;         // MongoDB-compatible connection string
  database: string;    // Database name
  tls?: boolean;       // Enable TLS (default: true for DocumentDB)
  tlsCaFile?: string;  // Path to the AWS DocumentDB CA bundle (.pem)
  entities?: CollectionDefinition[]; // Collections to auto-create on connect
}

interface CollectionDefinition {
  name: string;
  indexes?: Array<{
    name: string;
    fields: Record<string, 1 | -1>;
    unique?: boolean;
  }>;
}

Local development

Use a standard MongoDB instance with tls: false to develop locally:

const db = new DocumentDbProvider({
  uri: 'mongodb://localhost:27017',
  database: 'myapp',
  tls: false,
});

Or with Docker:

docker run -p 27017:27017 mongo:7

License

MIT