Registry / database / stream-to-mongo-db

stream-to-mongo-db

JSON →
library1.6.0jsnpmunverified

Stream objects directly into MongoDB collections using a configurable writable stream. Version 1.6.0 (last released in 2019) supports Node 8+ and provides batch write control to optimize insert performance. Differentiated by its simple streaming interface, it works with any readable stream (MongoDB cursors, Mongoose queries, S3 files, HTTP APIs) and allows transformation before write. The package is minimal with no external runtime dependencies beyond mongodb.

npm install stream-to-mongo-db
INSTALL
IMPORT
SIG · STREAM-TO-MONGO-DB
S
stream-to-mongo-db
databasejavascriptv1.6.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.

streamToMongoDB
import { streamToMongoDB } from 'stream-to-mongo-db'
const streamToMongoDB = require('stream-to-mongo-db')
Default export does not exist; use named import. For CommonJS use require('stream-to-mongo-db').streamToMongoDB
streamToMongoDB
const { streamToMongoDB } = require('stream-to-mongo-db')
const streamToMongoDB = require('stream-to-mongo-db')
CommonJS users must destructure the named export; require returns an object with the function.
streamToMongoDB
import { streamToMongoDB } from 'stream-to-mongo-db'
import streamToMongoDB from 'stream-to-mongo-db'
There is no default export. Use named import with braces.

Shows creating a writable stream with config, writing documents, and ending the stream.

import { streamToMongoDB } from 'stream-to-mongo-db'; const outputDBConfig = { dbURL: process.env.MONGO_URL ?? 'mongodb://localhost:27017/mydb', collection: 'myCollection', batchSize: 100 }; const writableStream = streamToMongoDB(outputDBConfig); // Example: writing a few documents const docs = [{ name: 'Alice' }, { name: 'Bob' }]; docs.forEach(doc => writableStream.write(doc)); writableStream.end(() => console.log('done'));
Debug
Known issues
gotchaThe package is no longer actively maintained; last release was in 2019. MongoDB driver updates may cause incompatibilities.
fix
Consider using mongodb writestream directly or a more modern alternative.
affects: >=1.6.0
deprecatedThe default export does not exist; using require('stream-to-mongo-db') will return an object with streamToMongoDB, not the function itself.
fix
Use destructured import: const { streamToMongoDB } = require('stream-to-mongo-db').
affects: >=1.0.0
gotchaThe writable stream expects objects to be written; it does not accept Buffer or string data.
fix
Ensure data written to the stream are plain JavaScript objects serializable to BSON.
affects: >=1.0.0
gotchaThe stream does not support backpressure handling well; large datasets may cause memory issues if not configured with an appropriate batchSize.
fix
Set a reasonable batchSize (e.g., 100-1000) to limit memory usage.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: streamToMongoDB is not a function
Using require('stream-to-mongo-db') directly which returns an object, not the function.
fix
Use const { streamToMongoDB } = require('stream-to-mongo-db');
TypeError: writableStream.write is not a function
streamToMongoDB returned a Readable stream instead of Writable due to incorrect import or package loading.
fix
Ensure you have destructured the named export correctly. Check that the package is installed and version is 1.x.
MongoError: not authorized on admin to execute command
The dbURL may point to a database where the user lacks write permissions on the target collection.
fix
Use a connection string with proper credentials and target database: 'mongodb://user:pass@host:port/dbname'
Upgrade
Version history
1.6.0latest on npm
Audit
Dependencies
mongodbrequiredUses MongoClient for database connection and operations
Agent activity
12 hits · last 30 days
node
10
Meta
1
OpenAI (training)
1
Resources
stream-to-mongo-db — npm install stream-to-mongo-db · libregistry