CSMongo.Commands.MongoDatabaseCommands.CopyDatabase C# (CSharp) Method

CopyDatabase() public static method

Copies a database from one location to another
public static CopyDatabase ( MongoDatabase database, string from, string to, string host, int port, string username, string password ) : MethodResult
database MongoDatabase
from string
to string
host string
port int
username string
password string
return CSMongo.Results.MethodResult
        public static MethodResult CopyDatabase(MongoDatabase database, string from, string to, string host, int port, string username, string password)
        {
            //create the request
            BsonObject parameters = new BsonObject(new {
                copydb = Mongo.CommandArgument,
                fromdb = from,
                todb = to,
                fromhost = host
            });

            //check for credentials
            username = (username ?? string.Empty).Trim();
            password = (password ?? string.Empty);

            //check for credentials
            if (string.IsNullOrEmpty(username) || string.IsNullOrEmpty(password)) {

                //get the connection information for the target database
                using (MongoDatabase target = new MongoDatabase(to, host)) {
                    GetNonceResult nonce = MongoDatabaseCommands.GetNonce(target);
                    string key = MongoDatabaseCommands.HashPassword(username, password, nonce.Nonce);

                    //and add it to the command
                    parameters += new {
                        username = username,
                        nonce = nonce,
                        key = key
                    };

                }

            }

            //finally, with the created value, send the command
            CommandResponse response = MongoDatabaseCommands.RunCommand(database, parameters);
            return new MethodResult(response.GetDefaultResponse());
        }