Skip to content

Instantly share code, notes, and snippets.

@louicoder
Last active September 25, 2020 08:34
Show Gist options
  • Save louicoder/9eecb66fab3c67daa30f373b599f33be to your computer and use it in GitHub Desktop.
Save louicoder/9eecb66fab3c67daa30f373b599f33be to your computer and use it in GitHub Desktop.
Copy collection from one database to another.
  1. login to the mongodb shell.
  2. go to dabase using command use <database_name>.
db.<your_collection_name_to_copy>.find().forEach(function(yourVariableName){
   db.getSiblingDB('<your_destination_atabase>')['<new_collection_name>'].insert(yourVariableName);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment