1. Home
  2. MongoDB
  3. MongoDB Tutorial
  4. MongoDB – Rename Collection

MongoDB – Rename Collection

MongoDB Rename Collection

Use db.collection.renameCollection() method to rename existing collection in MongoDB database.

Syntax:

db.collection.renameCollection(target, dropTarget)

Example:

For example, You have a collection with wrong spelling “pproducts“. Let’s use the following command on mongo Shell to correct collection name to “products“.

db.pproducts.renameCollection("products")

Output:

{ "ok" : 1 }
Tags ,
Was this article helpful to you? Yes 2 No
Advertisement