use node.js to copy from one mongo db to another
✓ Published0🌍 Public
RRandomEtc
Last edited Sep 15, 2011
Created on Sep 15, 2011
This example shows how to copy a MongoDB collection from one database to another using Node.js. The script opens both source and target databases via `mongodb.Server` and `mongodb.Db`, authenticates with credentials parsed from the URLs, then uses `sourceCollection.find().toArray()` and `targetCollection.insert()` to move all documents. It relies on the native MongoDB driver and Node’s `url.parse` for connection details, logging the number of inserted documents on success or exiting with an error otherwise.
AI-generated description