{"id":44006,"library":"stream-to-mongo-db","title":"stream-to-mongo-db","description":"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.","status":"maintenance","version":"1.6.0","language":"javascript","source_language":"en","source_url":"https://github.com/AbdullahAli/stream-to-mongo-db","tags":["javascript","stream","mongo","mongodb","pipe","stream to mongodb","stream to mongo db","stream to mongo","mongo stream"],"install":[{"cmd":"npm install stream-to-mongo-db","lang":"bash","label":"npm"},{"cmd":"yarn add stream-to-mongo-db","lang":"bash","label":"yarn"},{"cmd":"pnpm add stream-to-mongo-db","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Uses MongoClient for database connection and operations","package":"mongodb","optional":false}],"imports":[{"note":"Default export does not exist; use named import. For CommonJS use require('stream-to-mongo-db').streamToMongoDB","wrong":"const streamToMongoDB = require('stream-to-mongo-db')","symbol":"streamToMongoDB","correct":"import { streamToMongoDB } from 'stream-to-mongo-db'"},{"note":"CommonJS users must destructure the named export; require returns an object with the function.","wrong":"const streamToMongoDB = require('stream-to-mongo-db')","symbol":"streamToMongoDB","correct":"const { streamToMongoDB } = require('stream-to-mongo-db')"},{"note":"There is no default export. Use named import with braces.","wrong":"import streamToMongoDB from 'stream-to-mongo-db'","symbol":"streamToMongoDB","correct":"import { streamToMongoDB } from 'stream-to-mongo-db'"}],"quickstart":{"code":"import { streamToMongoDB } from 'stream-to-mongo-db';\n\nconst outputDBConfig = {\n  dbURL: process.env.MONGO_URL ?? 'mongodb://localhost:27017/mydb',\n  collection: 'myCollection',\n  batchSize: 100\n};\n\nconst writableStream = streamToMongoDB(outputDBConfig);\n\n// Example: writing a few documents\nconst docs = [{ name: 'Alice' }, { name: 'Bob' }];\ndocs.forEach(doc => writableStream.write(doc));\nwritableStream.end(() => console.log('done'));","lang":"typescript","description":"Shows creating a writable stream with config, writing documents, and ending the stream."},"warnings":[{"fix":"Consider using mongodb writestream directly or a more modern alternative.","message":"The package is no longer actively maintained; last release was in 2019. MongoDB driver updates may cause incompatibilities.","severity":"gotcha","affected_versions":">=1.6.0"},{"fix":"Use destructured import: const { streamToMongoDB } = require('stream-to-mongo-db').","message":"The default export does not exist; using require('stream-to-mongo-db') will return an object with streamToMongoDB, not the function itself.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Ensure data written to the stream are plain JavaScript objects serializable to BSON.","message":"The writable stream expects objects to be written; it does not accept Buffer or string data.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set a reasonable batchSize (e.g., 100-1000) to limit memory usage.","message":"The stream does not support backpressure handling well; large datasets may cause memory issues if not configured with an appropriate batchSize.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.6.0':18 '2019':22 '8':25 'allow':56 'api':54 'batch':28 'beyond':69 'collect':11 'configur':14 'control':30 'cursor':48 'db':5,82 'depend':68 'differenti':35 'direct':8 'extern':66 'file':52 'http':53 'insert':33 'interfac':40 'javascript':71 'last':19 'minim':63 'mongo':4,73,81,85,86 'mongodb':10,47,70,74,78 'mongoos':49 'node':24 'object':7 'optim':32 'packag':61 'perform':34 'pipe':75 'provid':27 'queri':50 'readabl':45 'releas':20 'runtim':67 's3':51 'simpl':38 'stream':2,6,16,39,46,72,76,79,83,87 'stream-to-mongo-db':1 'support':23 'transform':57 'use':12 'version':17 'work':42 'writabl':15 'write':29,59","created_at":"2026-06-05T17:02:31.281610+00:00","updated_at":"2026-06-05T17:02:31.281610+00:00","problems":[{"fix":"Use const { streamToMongoDB } = require('stream-to-mongo-db');","cause":"Using require('stream-to-mongo-db') directly which returns an object, not the function.","error":"TypeError: streamToMongoDB is not a function"},{"fix":"Ensure you have destructured the named export correctly. Check that the package is installed and version is 1.x.","cause":"streamToMongoDB returned a Readable stream instead of Writable due to incorrect import or package loading.","error":"TypeError: writableStream.write is not a function"},{"fix":"Use a connection string with proper credentials and target database: 'mongodb://user:pass@host:port/dbname'","cause":"The dbURL may point to a database where the user lacks write permissions on the target collection.","error":"MongoError: not authorized on admin to execute command"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/AbdullahAli/stream-to-mongo-db","github":"https://github.com/AbdullahAli/stream-to-mongo-db","docs":null,"changelog":null,"pypi":null,"npm":"stream-to-mongo-db","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}