เปลี่ยนชื่อ Collection ด้วย renameCollection()
ใช้ Method renameCollection() เพื่อเปลี่ยนชื่อ Collection
db.yourOldCollectionName.renameCollection('yourNewCollectionName');
ตัวอย่างการเปลี่ยนชื่อ
> use sample; switched to db sample > show collections;
copyThisCollectionToSampleDatabaseDemo deleteDocuments deleteDocumentsDemo employee informationAboutDelete internalArraySizeDemo prettyDemo selectWhereInDemo sourceCollection updateInformation userInformation
เปลี่ยนชื่อ informationAboutDelete เป็น deleteSomeInformation
> db.informationAboutDelete.renameCollection('deleteSomeInformation');
{ "ok" : 1 }
ตรวจสอบรายการ Collections ใหม่
> show collections;
copyThisCollectionToSampleDatabaseDemo deleteDocuments deleteDocumentsDemo deleteSomeInformation employee internalArraySizeDemo prettyDemo selectWhereInDemo sourceCollection updateInformation userInformation
Collection ถูกเปลี่ยนชื่อเรียบร้อยแล้ว