Registry / database / fortune-mongodb

fortune-mongodb

JSON →
library1.3.2jsnpmunverified

MongoDB adapter for the Fortune.js ORM-like library. Current stable version is 1.3.2. Release cadence is low, with the last release in 2019. It uses the official MongoDB Node.js driver internally and supports transactions, custom ID generation, and type-to-collection mapping. Differentiators: integrates directly with Fortune's API, supports transactions, and allows arbitrary queries via the find method's query function. Requires Node.js >=8 and Fortune.js as a peer dependency.

npm install fortune-mongodb
INSTALL
IMPORT
SIG · FORTUNE-MONGODB
F
fortune-mongodb
databasejavascriptv1.3.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const mongodbAdapter = require('fortune-mongodb')
import mongodbAdapter from 'fortune-mongodb'; // CommonJS package, use require
This package provides a CommonJS module. ESM import not supported unless using a bundler with interop.
fortune
const fortune = require('fortune')
import fortune from 'fortune'; // Fortune is CommonJS
Fortune is also CommonJS; both packages must be required similarly.
adapter
adapter: [mongodbAdapter, { url: '...' }]
adapter: { adapter: mongodbAdapter, url: '...' } // Incorrect: adapter option expects an array
The adapter option in Fortune expects an array where the first element is the adapter function and the second element is an options object.

Demonstrates setting up Fortune with the MongoDB adapter, defining a simple schema with two record types (user and post), and performing a find operation.

const fortune = require('fortune'); const mongodbAdapter = require('fortune-mongodb'); // Define a simple schema const store = fortune({ user: { name: String, posts: [ { ref: 'post', inverse: 'author' } ] }, post: { title: String, author: { ref: 'user', inverse: 'posts' } } }, { adapter: [ mongodbAdapter, { url: process.env.MONGO_URL || 'mongodb://localhost:27017/test' } ] }); // Use the store store.find('user', 1).then(console.log).catch(console.error);
Debug
Known issues
breakingfortune-mongodb requires fortune as a peer dependency; incompatible versions may cause runtime errors.
fix
Ensure fortune version matches the adapter's requirements; see package.json peerDependencies.
affects: all
gotchaThe adapter option in Fortune must be an array, not an object.
fix
Use adapter: [adapterFunction, optionsObject] instead of adapter: { adapter: ..., url: ... }.
affects: all
deprecatedThe package uses the deprecated MongoDB driver callback-style API; no official support for newer driver features.
fix
Consider using a more modern adapter or updating the driver manually.
affects: >=1.0.0
gotchaTransactions (enableTransactions: true) require MongoDB to be running as a replica set; otherwise, writes will fail.
fix
Ensure your MongoDB instance is configured as a replica set before enabling transactions.
affects: >=1.0.0
gotchaCustom ID generation (generateId) function must return a unique value per type; no validation is performed.
fix
Provide a function that returns globally unique IDs, e.g., using uuid.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'fortune'
fortune is not installed as a peer dependency.
fix
Run npm install fortune fortune-mongodb to install both packages.
TypeError: adapter is not a function
Adapter option is not passed as an array (first element is the adapter function).
fix
Correct usage: adapter: [require('fortune-mongodb'), { url: '...' }]
MongoError: Transactions are not supported by this deployment
enableTransactions is true but MongoDB is not running as a replica set.
fix
Either set enableTransactions: false or configure MongoDB as a replica set.
Error: connect ECONNREFUSED 127.0.0.1:27017
MongoDB server is not running or the URL is incorrect.
fix
Start MongoDB (e.g., mongod) or check the url option.
Upgrade
Version history
1.3.2latest on npm
Audit
Dependencies
fortunerequiredPeer dependency; this adapter requires Fortune.js to function.
Agent activity
2 hits · last 30 days
node
2
Resources
fortune-mongodb — npm install fortune-mongodb · libregistry