Skip to content

Latest commit

 

History

History
27 lines (18 loc) · 681 Bytes

how-to-rename-a-mongodb-collection.md

File metadata and controls

27 lines (18 loc) · 681 Bytes

How to rename a MongoDB collection?

// plain

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

db.collection.renameCollection("newCollectionName")

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

onelinerhub: How to rename a MongoDB collection?