9951 explained code solutions for 126 technologies

mongodbHow to rename a MongoDB collection?

MongoDB collections can be renamed using the renameCollection() method.


This method takes two parameters:

  1. The current collection name
  2. 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

Edit this code on GitHub