copyTo will copy the data from one collection to other including all the Associated content.

Example:


db.studentDetails.copyTo("sDetails")



The above command will copy the data from ‘studentDetails’ collection to ‘sDetails’, here there is not necessary that sDetails to be already exists.

Note: While copying the Data, MongoDB will not allow for read or write operations.