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 join two collections in MongoDB?
- How to work with time series data in MongoDB?
- How to list MongoDB users?
- How to remove a field from MongoDB?
- How to use watch in MongoDB?
- How to use unwind in MongoDB?
- How to use transactions in MongoDB?
- How to implement pagination in MongoDB?
- How to check the version of MongoDB?
- How to update an array element in MongoDB?
See more codes...