Registry / database / mongojson

mongojson

JSON →
library0.1.2jsnpmunverified

MongoDB-compatible SDK for json-server (v0.1.2). Provides a MongoDB-like query interface (find, insertOne, updateOne, deleteOne, countDocuments) on top of a REST API. Designed to work with JSON Server instances, allowing developers to use familiar MongoDB operations without a full MongoDB backend. Includes TypeScript types. Released as a single version; no major updates yet. Differentiator: bridges MongoDB syntax with REST endpoints for quick prototyping.

npm install mongojson
INSTALL
IMPORT
SIG · MONGOJSON
M
mongojson
databasejavascriptv0.1.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.

MongoClient
import { MongoClient } from 'mongojson'
const MongoClient = require('mongojson')
ESM-only package; CommonJS require will fail.
Db
import { Db } from 'mongojson'
Type export for TypeScript users; not commonly used directly.
Collection
import { Collection } from 'mongojson'
Type export for TypeScript users; not commonly used directly.

Demonstrates full CRUD and count using MongoDB-like syntax with mongojson against a JSON Server backend.

import { MongoClient } from 'mongojson'; const uri = 'mongodb://dbuser:dbpass@yourusername.json.shahriyar.dev/mydb'; const client = new MongoClient(uri); await client.connect(); const db = client.db(); const users = db.collection('users'); // Create await users.insertOne({ name: 'Alice', age: 30 }); // Read const all = await users.find().toArray(); const alice = await users.findOne({ name: 'Alice' }); // Update await users.updateOne({ name: 'Alice' }, { $set: { age: 31 } }); // Delete await users.deleteOne({ name: 'Alice' }); // Count const total = await users.countDocuments(); console.log('Success!');
Debug
Known issues
gotchaThe MongoDB-like operations are only supported on JSON Server instances that implement the expected REST endpoints. Not compatible with actual MongoDB databases.
fix
Ensure your backend is a JSON Server instance supporting mongojson operations.
affects: >=0.0.0
gotchaConnection URI must match the JSON Server format 'mongodb://user:pass@host/db'. Using a standard MongoDB URI will fail.
fix
Use the correct URI format as shown in the documentation.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'mongojson'
Package not installed or imported incorrectly in CommonJS.
fix
Run 'npm install mongojson' and use ESM import syntax.
TypeError: client.connect is not a function
Attempting to call connect before creating a client or using wrong import.
fix
Ensure you use `new MongoClient(uri)` and then call `await client.connect()`.
Upgrade
Version history
0.1.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
Resources
mongojson — npm install mongojson · libregistry