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());
}