Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Web Technology by (50.2k points)

Can you please guide me for renaming a collection in mongo? Something like:

db.originalCollectionName.rename('newCollectionName');

1 Answer

0 votes
by (108k points)
edited by

For your task, there is a function db.collection.renameCollection() in MongoDB which will help you to change the name of the collection, refer to the following code:

db.collection.renameCollection(target, dropTarget)

  • target: new name of the collection inside single quotations(‘new_name_of_the_collection’)

  • dropTarget: this parameter is optional. dropTarget is of boolean value and by default it is false. If this value is true then the mongod drops the target of renameCollection before renaming the collection. 

If you want to learn more about MongoDB then go through this MongoDB course for more insights.

MongoDB is an important part of full-stack development. Enroll in this Full Stack Developer Training to start your journey in this field.

Related questions

0 votes
1 answer
0 votes
2 answers
0 votes
2 answers
0 votes
2 answers
0 votes
1 answer

Browse Categories

...