skip to Main Content

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)

2

Answers


  1. Chosen as BEST ANSWER

    To backup my collection manually I did this:

    1. In the same project, created a file called backup.js that is called when I press a backup button.
    2. 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.
    3. 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);
      }
    }
    

  2. I use firefoo… there is trial version for 14 days

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search