How to replace copydb from client code?

In MongoDB version 4.2 command copydb has been removed. We used it to create databases from template in the NodeJS client code, like this (reusing the existing connection to the admin db):

         db.command({ copydb: 1, fromdb: "tenant_template", todb: tenant.id }, (err, col) => {
                callback(err);
         });

Recommended replacement commands mongodump and mongorestore are shell commands (not mongo shell) and seem to require full connection parameters with user name and password, which are not accessible in that part of code. Can someone suggest a way to create a new database on the cluster to which connection already exist with NodeJS client, and to place some predefined content into that database? We can do it fully programmatically as well, not necessary to copy from a template database.

Thanks.

You could try with $out or $merge.

Slightly, more complicated since you have to do it for each collections.