Notes on using MongoDB command line tools to export/import MongoDB collections

Note: This post is a details-post for the post: Learning web app development through free online tutorials – Organized Notes and Log, https://raviswdev.blogspot.com/2024/03/learning-web-app-development-through.html .

Atlas M0 (Free Cluster), M2, and M5 Limits, https://www.mongodb.com/docs/atlas/reference/free-shared-limitations/ clearly states, "You can't enable backups on M0 free clusters.". But it mentions that (MongoDB) command line tools can be used to do such backup.

...

https://www.mongodb.com/docs/atlas/command-line-tools/ 

In https://www.mongodb.com/try/download/database-tools, choose 'MongoDB Command Line Database Tools Download' by scrolling down the page (not listed on left pane). The filename of download (for Windows) is: mongodb-database-tools-windows-x86_64-100.9.4.msi .

mongosh-2.1.5-x64.msi is MongoDB shell which is NOT what we want for backup/restore/export/import.

...

https://www.mongodb.com/docs/atlas/command-line-tools/ gives instructions on how to "Choose Command Line Tools for your desired cluster". Followed that and got another page whose section 'Data Import and Export Tools' has the specific commands for export and import of collections in my cluster. 

After mongodb-database-tools-windows-x86_64-100.9.4.msi  install into D drive with binary files path: D:\Program Files\MongoDB\Tools\100\bin , and adding binary files path to PATH env. var. for user, I was able to successfully run mongoexport and mongoimport commands with json as the file type setting. mongoexport for posts collection produced a json file stored on my PC. I used that to do mongoimport to a differently named new collection back-posts which got created on MongoDB with what seems to be same data as in posts collection.

Comments

Archive