Skip to content

Commit d02c35e

Browse files
author
rstam
committed
More work on CSHARP-402. Added overloads of RenameCollection that have an adminCredentials parameter.
1 parent cb573d8 commit d02c35e

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

Driver/Core/MongoDatabase.cs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -774,10 +774,25 @@ public virtual CommandResult RenameCollection(string oldCollectionName, string n
774774
/// <param name="newCollectionName">The new name for the collection.</param>
775775
/// <param name="dropTarget">Whether to drop the target collection first if it already exists.</param>
776776
/// <returns>A CommandResult.</returns>
777+
public virtual CommandResult RenameCollection(string oldCollectionName, string newCollectionName, bool dropTarget)
778+
{
779+
var adminCredentials = _server.Settings.GetCredentials("admin");
780+
return RenameCollection(oldCollectionName, newCollectionName, dropTarget, adminCredentials);
781+
}
782+
783+
/// <summary>
784+
/// Renames a collection on this database.
785+
/// </summary>
786+
/// <param name="oldCollectionName">The old name for the collection.</param>
787+
/// <param name="newCollectionName">The new name for the collection.</param>
788+
/// <param name="dropTarget">Whether to drop the target collection first if it already exists.</param>
789+
/// <param name="adminCredentials">Credentials for the admin database.</param>
790+
/// <returns>A CommandResult.</returns>
777791
public virtual CommandResult RenameCollection(
778792
string oldCollectionName,
779793
string newCollectionName,
780-
bool dropTarget)
794+
bool dropTarget,
795+
MongoCredentials adminCredentials)
781796
{
782797
MongoCollection.ValidateCollectionName(newCollectionName);
783798
var command = new CommandDocument
@@ -786,8 +801,20 @@ public virtual CommandResult RenameCollection(
786801
{ "to", string.Format("{0}.{1}", _name, newCollectionName) },
787802
{ "dropTarget", dropTarget, dropTarget } // only added if dropTarget is true
788803
};
789-
var adminDatabase = _server.GetDatabase("admin");
790-
return adminDatabase.RunCommand(command); // TODO: can we run this command against this database?
804+
var adminDatabase = _server.GetDatabase("admin", adminCredentials);
805+
return adminDatabase.RunCommand(command);
806+
}
807+
808+
/// <summary>
809+
/// Renames a collection on this database.
810+
/// </summary>
811+
/// <param name="oldCollectionName">The old name for the collection.</param>
812+
/// <param name="newCollectionName">The new name for the collection.</param>
813+
/// <param name="adminCredentials">Credentials for the admin database.</param>
814+
/// <returns>A CommandResult.</returns>
815+
public virtual CommandResult RenameCollection(string oldCollectionName, string newCollectionName, MongoCredentials adminCredentials)
816+
{
817+
return RenameCollection(oldCollectionName, newCollectionName, false, adminCredentials); // dropTarget = false
791818
}
792819

793820
/// <summary>

0 commit comments

Comments
 (0)