Registry / database / grafio-mongo

grafio-mongo

JSON →
library3.15.1jsnpmunverified

MongoDB storage backend for grafio, a graph database with a pluggable storage architecture. Current stable version is 3.15.1. Requires MongoDB >= 5.0.0 and grafio runtime. Ships TypeScript types. Release cadence is not specified; updates follow grafio core. Key differentiator: provides persistent graph storage with native MongoDB transactions, optimized indexes for nodes/edges, and multi-graph partitioning via graphId.

npm install grafio-mongo
INSTALL
IMPORT
SIG · GRAFIO-MONGO
G
grafio-mongo
databasejavascriptv3.15.1
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.

MongoGraphFactory
import { MongoGraphFactory } from 'grafio-mongo'
const MongoGraphFactory = require('grafio-mongo').MongoGraphFactory
ESM-only; named export. CommonJS require works but destructure named export.
MongoGraph
import { MongoGraph } from 'grafio-mongo'
import MongoGraph from 'grafio-mongo'
Named export, not default. Type includes generic for node/edge types.
ensureIndexes
const factory = new MongoGraphFactory(db); await factory.ensureIndexes();
MongoGraphFactory.ensureIndexes()
Instance method, not static. Must be called on factory instance.

Creates a MongoDB-backed graph factory, ensures indexes, and performs basic node/edge operations.

import { MongoClient } from 'mongodb'; import { MongoGraphFactory } from 'grafio-mongo'; async function main() { const client = new MongoClient(process.env.MONGO_URI ?? 'mongodb://localhost:27017'); await client.connect(); const db = client.db('grafio'); const factory = new MongoGraphFactory(db); await factory.ensureIndexes(); const graph = factory.forGraph('demo'); graph.addNode('User', { name: 'Alice', age: 30 }); graph.addNode('City', { name: 'New York' }); graph.addEdge('LIVES_IN', 'alice', 'nyc', { since: 2020 }); console.log('Graph operations completed'); await client.close(); } main().catch(console.error);
Debug
Known issues
breakingv3.0.0 changed MongoDB driver peer dependency from mongodb@4 to mongodb@5. Older code using mongodb@4 requires driver update.
fix
Update mongodb driver to version 5 or later: npm install mongodb@5
affects: >=3.0.0
breakingv2.0.0 removed legacy callback API. All async operations return Promises.
fix
Use async/await or .then() for all operations; remove callback parameters.
affects: >=2.0.0
deprecatedThe `useTransactions` option in construction is deprecated. Transactions are now always enabled.
fix
Remove `useTransactions` option from MongoGraphFactory constructor.
affects: >=2.5.0
gotchaThe `nodeId` parameter in `addEdge` must be a string, not a MongoDB ObjectId. Throws runtime error if ObjectId is passed.
fix
Convert ObjectId to string with `.toString()` before passing as nodeId.
affects: >=1.0.0
gotchaBoth `grafio` and `mongodb` peer dependencies must be installed separately. Missing one will cause import errors.
fix
Install both: npm install grafio mongodb
affects: >=1.0.0
breakingv1.5.0 renamed `graphId` property to `graphName` in configuration objects. Old property no longer works.
fix
Replace `graphId:` with `graphName:` in configuration.
affects: >=1.5.0
Errors
Common errors & fixes
Cannot find module 'grafio-mongo' or its corresponding type declarations.
Missing peer dependency 'grafio' or 'mongodb'.
fix
Install required peers: npm install grafio mongodb
TypeError: factory.ensureIndexes is not a function
Calling ensureIndexes before constructing factory, or using old API.
fix
Ensure factory is created: const factory = new MongoGraphFactory(db); then await factory.ensureIndexes();
MongoServerError: E11000 duplicate key error collection
Attempting to add a node with an id that already exists in the graph.
fix
Use graph.updateNode() to modify existing nodes, or ensure unique ids per graph.
TypeError: graph.addEdge is not a function
Using older version where method was named 'addRelation' or 'connect'.
fix
Update to grafio-mongo@3 and use addEdge, or check version's API docs.
Error: Invalid nodeId: must be a string
Passing a MongoDB ObjectId instead of a string for node or edge ID parameters.
fix
Convert ObjectId to string: nodeId.toString()
Upgrade
Version history
3.15.1latest on npm
Audit
Dependencies
mongodboptionalMongoDB driver for database connectivity, native driver version must be compatible
Agent activity
10 hits · last 30 days
node
10
Resources