[CSHARP-706] Add MongoCollection.RenameCollection Created: 19/Mar/13 Updated: 20/Mar/14 Resolved: 27/Mar/13 |
|
| Status: | Closed |
| Project: | C# Driver |
| Component/s: | None |
| Affects Version/s: | 1.8 |
| Fix Version/s: | None |
| Type: | New Feature | Priority: | Major - P3 |
| Reporter: | Tim Kellogg | Assignee: | Robert Stam |
| Resolution: | Won't Fix | Votes: | 0 |
| Labels: | renameCollection | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Description |
|
This method is different from MongoDatabase.RenameCollection. One is an admin operation, the other isn't. I wrote an extension method that holds me over: public static BsonValue RenameCollection<T>(this MongoCollection<T> collection, string newName) .renameCollection(' {1}');".Inject(collection.Name, newName); |
| Comments |
| Comment by Robert Stam [ 19/Mar/13 ] |
|
Version 2.4 of the server doesn't require admin credentials to use RenameCollection. There is a reason that we don't have a Rename (or RenameCollection) method in MongoCollection. The name of the collection is part of the identity of the MongoCollection object, so we can't change the name of an existing MongoCollection object (it would continue to refer to the old name even if the database name had changed). While it is true that version 2.2 of the server returns an error in this case if you don't have admin credentials, I'm not sure that the driver needs a workaround since server 2.4 has already shipped. |
| Comment by Tim Kellogg [ 19/Mar/13 ] |
|
db.renameCollection is an authorized operation. If you're running mongo 2.2 with auth you'll get an error if you're not an admin user. db.collection.renameCollection is not an admin operation |
| Comment by Robert Stam [ 19/Mar/13 ] |
|
Why don't you just use MongoDatabase.RenameCollection? I get that your code has implemented the rename operation differently, just not why you couldn't use MongoDatabase.RenameCollection. |