mongo-copydb
The copydb command has been deprecated as of mongoDB version 4.0 and no longer available in versions >= 4.2. This plugin is designed to help compensate for this change in behavior. It copies a mongodb database from one mongod instance to the same instance or another using node.js.
Installation
$ npm install mongo-copydb
Requirements
The plugin depends on mongodump
and mongorestore
to perform the copy command. Make sure these utilities are installed and included in the search path. They are incuded in the normal mongDB installation package and should be readily available if mongoDB is installed and functioning properly.
Usage
copydb(fromdb, todb, options)
fromdb: Name of source database
todb: Name of target database
options: {
fromhost: Hostname of the source mongod instance.
Default = localhost:27017
tohost: Hostname of the target mongod instance
Default = localhost:27017
username: The name of the user on the fromhost MongoDB instance
Default = <none>
password: The password on the fromhost for authentication
Default = <none>
}
Example
const copydb = ; { // Create copy on same default mongod instance await ; // Create copy from default to other mongod instance await ; // Create copy between two mongod instances with user creds // Note: username and password are both required await ;}