How does MongoDB Cluster Copy Collection Efficiently

  mongodb, question

At present, there is a MongoDB cluster. There is a Collection A in the cluster. A new Collection B is created. You want to copy the data in Collection A to Collection B through Mongos. What is the efficient implementation?

At present, there are two ways to copy the Collection:
1, mentioned in the official documentsdb.cloneCollection(from, collection, query), this method cannot be operated through Mongos, and it copies the remote Collection to the local, which does not seem to meet the requirements.
2. use script to traverse Collection A and insert data into Collection B one by one.

Db. copy source table. find().forEach(function(x){
 Db. destination table. insert(x);
 })

This kind of implementation meets the requirements, but there is another problem: querying the source table one by one and inserting it into the new table will definitely have a lot of overhead (the amount of data is about 4000w, about 100GB).

I’d like to ask Daniel, is there any more efficient and convenient way to meet the requirement of topic design? If there is no more convenient method, what can be improved about the above two methods?
Thank you!

Your second method, you can monitor yourMongoDbThe state of the cluster, when more idle to recycle your data, if monitoring your cluster load is relatively large, stop copying. Wait until the next time the cluster is monitored to be idle, and start at the place where the last replication was resumed.