@@ -774,10 +774,25 @@ public virtual CommandResult RenameCollection(string oldCollectionName, string n
774
774
/// <param name="newCollectionName">The new name for the collection.</param>
775
775
/// <param name="dropTarget">Whether to drop the target collection first if it already exists.</param>
776
776
/// <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>
777
791
public virtual CommandResult RenameCollection (
778
792
string oldCollectionName ,
779
793
string newCollectionName ,
780
- bool dropTarget )
794
+ bool dropTarget ,
795
+ MongoCredentials adminCredentials )
781
796
{
782
797
MongoCollection . ValidateCollectionName ( newCollectionName ) ;
783
798
var command = new CommandDocument
@@ -786,8 +801,20 @@ public virtual CommandResult RenameCollection(
786
801
{ "to" , string . Format ( "{0}.{1}" , _name , newCollectionName ) } ,
787
802
{ "dropTarget" , dropTarget , dropTarget } // only added if dropTarget is true
788
803
} ;
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
791
818
}
792
819
793
820
/// <summary>
0 commit comments