I have hundreds of entries in my firebase database and I'd like to try moving to SQL in case my Firebase free plan ever goes out of limit. Is there any way I can export the data in JSON format without buying the Blaze plan? (as my card doesn't work when I try to do payment)
Asked
Active
Viewed 582 times
1
-
1From [the docs](https://firebase.google.com/docs/firestore/manage-data/export-import#before_you_begin)... _"Only Google Cloud projects with billing enabled can use the export and import functionality."_. You can probably still get by within the free limits – Phil Jul 14 '22 at 05:47
-
1Depending on the complexity of the data, it may be straight forward to create a small app to iterate through your collections and dump the documents into a JSON flat file. But... If you have not tried SQL with JSON data before, I would suggest you try it first with some sample data before spending time trying to export it. You may change your mind and re-tooling an app from NoSQL/JSON into something MySQL'ish could be a time consuming exercise. – Jay Jul 14 '22 at 18:05
-
@Phil Yes but unfortunately, my cards don't work with their system. I always get a payment failed error. – Wor Chan Jul 15 '22 at 06:46
2 Answers
2
To backup my collection manually I did this:
- In the same project, created a file called backup.js that is called when I press a backup button.
- In the backup.js endpoint, I fetch the collection and store every entry in the database, then I return this array of documents I just saved.
- I console.log the returned data and in Browser's console, I right click the array output and click 'Copy Object' and save it in a text file.
backup.js (Next.js API Endpoint):
import { collection, doc, getDoc, getDocs } from "firebase/firestore";
import { StatusCodes } from "http-status-codes";
import { db } from "../../utils/firebase";
export default async function handler(req, res) {
const collectionName = "myCollection"
try {
// check firebase if slug exists
const documentSnapshot = await getDocs(collection(db, collectionName));
let backup = [];
documentSnapshot.forEach((doc) => {
backup.push(doc.data());
});
console.log(backup);
return res.status(StatusCodes.OK).send(backup);
} catch (err) {
console.log("Database Error", err);
}
}

Wor Chan
- 139
- 1
- 11
1
I use firefoo... there is trial version for 14 days

Jakub Smetanka
- 11
- 2
-
Your answer could be improved by providing an example of the solution and how it helps the OP. – Tyler2P Jul 17 '22 at 18:48