Saturday, May 4, 2024

Firebase to MongoDB Compass Migration Tutorial 2024!

Migrating your Firebase database can be pretty tough sometimes, especially considering the fact that there are just too many methods to achieve what we aim for. So in order to make it easy, I have written this brief tutorial on how to migrate your Firebase database to MongoDB Compass


Setup:-

Download the two RAR files from github LINK
Extract them and keep them in separate folders
Install node modules in both the folders using 
"npm install"

Firebase Setup:- 

Login to your firebase account and select the project you wish to transfer the database from.



After selecting the project, go to project settings,



After that go to service accounts, then generate new private key, rename the key to whatever name you want and store it in our FirebaseImportExport folder which we extracted.

Tutorial:-

After generating the private key and copying it to the FirebaseImportExport folder, we are now all set!


  • Now open terminal in the FirebaseImportExport folder and run the following command (ignore the " also make sure that the path is correct.)
 firestore-export --accountCredentials " PATH WHERE YOU HAVE DOWNLOADED YOUR KEY" -b collections.json
(This is how the path should be D:\FirebaseImportExport\Test.json)
  • Copy the generated collections.json file and paste it in our JSON TO MONGODB Folder which we extracted earlier.
  • Open the JSON TO MONGODB folder in your VS Code
  • Open your collections.json file



Modify the collections.json file. Remove the "__collections__": {

Now, modify the connection strings in app.js

After setting up the application, you can open terminal and write the command 
node app.js
And your database will start migrating to MongoDB Compass


Congratulations, you have migrated your firebase database to MongoDB Compass

Feel free to comment if you face any issues.

No comments:

Post a Comment

Firebase to MongoDB Compass Migration Tutorial 2024! Migrating your Firebase database can be pretty tough sometimes, especially considering ...