Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rename collection in document db?

Tags:

How to rename database name or collections name in azure document Db? We have set of collections in our documentdb database. Is it possible to change the collection name for other purposes

like image 612
vinoth Avatar asked Aug 30 '16 22:08

vinoth


People also ask

How do I rename a collection in MongoDB Atlas?

You can use the renameCollection function of MongoDB to change the collection name.

How do I rename a Sharded collection?

There is no way to rename a sharded collection. You can copy all the docs to a new collection. Or create multiple collections based on a weekly/period date, and use as the current one. Then have your application always use the current one by name and change the name at each period break.

How do I rename a document in MongoDB?

In MongoDB, you can rename a field when updating documents in a collection. To rename a field, call the $rename operator with the current name of the field and the new name. This renames the field in all matching documents that have a field with that name.

How do I rename a collection?

renameCollection() method is used to rename a collection. The new name of the collection. Enclose the string in quotes. If true, mongod drops the target of renameCollection prior to renaming the collection.


1 Answers

You cannot rename a database or collection. If you must have a different collection name, you'll need to create a new collection and copy your data over.

like image 179
David Makogon Avatar answered Oct 21 '22 12:10

David Makogon