Registry / database / simple-odata-server-mongodb

simple-odata-server-mongodb

JSON →
library1.0.0jsnpmunverified

Adapter for node-simple-odata-server that provides MongoDB persistence. Version 1.0.0 is stable but has infrequent updates (last release in 2023). It maps OData queries to MongoDB operations, supporting filtering, sorting, and pagination. Unlike generic OData servers, this integrates directly with the simple-odata-server ecosystem and uses native MongoDB driver. Minimal dependencies; requires mongodb v4+ and simple-odata-server v2+.

npm install simple-odata-server-mongodb
INSTALL
IMPORT
SIG · SIMPLE-ODATA-SERVE
S
simple-odata-server-mongodb
databasejavascriptv1.0.0
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
import adapter from 'simple-odata-server-mongodb'
const adapter = require('simple-odata-server-mongodb')
Package exports a default function; ESM preferred. For CJS, use require, but ensure .default is not needed.
MongoAdapter
import MongoAdapter from 'simple-odata-server-mongodb'
import { MongoAdapter } from 'simple-odata-server-mongodb'
There is no named export; it's a default export. TypeScript: import type definitions if needed.

Sets up an OData endpoint with MongoDB adapter using Express, defines a simple Product entity, and listens on port 3000.

import express from 'express'; import odataServer from 'simple-odata-server'; import adapter from 'simple-odata-server-mongodb'; import { MongoClient } from 'mongodb'; const app = express(); const model = { namespace: 'myapp', entityTypes: { Product: { _id: { type: 'String', key: true }, name: { type: 'String' }, price: { type: 'Decimal' } } }, entitySets: { Products: { entityType: 'Product' } } }; async function start() { const client = new MongoClient(process.env.MONGO_URI ?? 'mongodb://localhost:27017'); await client.connect(); const db = client.db('test'); const odata = odataServer(model).adapter(adapter(db)); app.use('/odata', odata.create()); app.listen(3000, () => console.log('OData server on :3000/odata')); } start().catch(console.error);
Debug
Known issues
breakingVersion 1.0.0 changed the adapter function signature from (collection) to (db) - now expects a MongoClient db object, not a collection.
fix
Pass db = client.db('name') instead of a single collection.
affects: >=1.0.0
gotchaRequires mongodb driver v4 or later; v3 may cause connection errors.
fix
Upgrade to mongodb v4+ or use an older version of this adapter (0.x).
affects: >=1.0.0
gotchaQuery options like $top, $skip, $filter are translated to MongoDB but $expand is not supported.
fix
Implement custom handling or avoid $expand in queries.
affects: >=1.0.0
breakingEntity keys must be named '_id' for MongoDB compatibility; custom key names break persistence.
fix
Use '_id' as key field in model definition.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: adapter is not a function
Incorrect import style (e.g., using named import for default export)
fix
Use `import adapter from 'simple-odata-server-mongodb'` or `const adapter = require('simple-odata-server-mongodb').default` (CJS).
MongoError: The `uri` parameter must be a string
MongoClient.connect called without proper URI or using db object directly
fix
Ensure you pass a MongoDB connection URI string to MongoClient.connect, then use client.db().
TypeError: Cannot read properties of undefined (reading 'collection')
Passed a MongoClient instance instead of a db object to adapter
fix
Use `adapter(db)` where db = client.db('databaseName').
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
simple-odata-serverrequiredCore OData server that this adapter extends
mongodbrequiredMongoDB driver for database operations
Agent activity
13 hits · last 30 days
node
10
Meta
2
Resources
simple-odata-server-mongodb — npm install simple-odata-server-mongodb · libregistry