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 the wrong spelling “pproducts“. Let’s use the following command on mongo Shell to correct the collection name to “products“.

db.pproducts.renameCollection("products")

Output:

{ "ok" : 1 }
Reactions

Post a Comment

0 Comments

close