mongodbHow to rename a MongoDB collection?
MongoDB collections can be renamed using the renameCollection()
method.
db.collection.renameCollection("newCollectionName")
This method takes two parameters:
- The current collection name
- The new collection name
The output of the above example code will be:
{ "ok" : 1 }
This indicates that the collection has been successfully renamed.
Helpful links
More of Mongodb
- How to use MongoDB HTTP interface?
- How to use triggers in MongoDB?
- How to kill an operation in MongoDB?
- How to use the limit operator in MongoDB?
- How to get all documents in MongoDB?
- How to export an entire MongoDB database?
- How to work with time series data in MongoDB?
- How to empty an array in MongoDB?
- How to use regex in MongoDB?
- What is MongoDB default port?
See more codes...