This code was created to copy a entire MongoDB collection via NodeJS.
- Before starting, be sure to change the following variables:
-
urlSource
-
urlTarget
-
dbSource
-
dbTarget
-
collectionSource
-
collectionTarget
-
chunks
- This variable refers to the number of documents to be copied for each connection to the database.
- You can leave the default value of 100 if desired.
- You can use a higher or lower number, depending on the performance of your server.
-
timeOut
- This variable refers to the timeout (in milliseconds) between each connection to the database.
- You can leave the default value of 7000 if desired.
- You can use a higher or lower number, depending on the performance of your server.
- You can even replace the line
setTimeout(copyDocumentsInChunks, timeOut, skip + limit, limit, count, collectionSource);
with
copyDocumentsInChunks(skip + limit, limit, count, collectionSource);
To completely remove the wait between the connections.