Created
October 13, 2019 14:25
-
-
Save iammarkps/98de4da8abec93d2002ee82801c4c431 to your computer and use it in GitHub Desktop.
programming.in.th | Tasks Backup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const admin = require('firebase-admin') | |
const fs = require('fs') | |
const serviceAccount = require('./grader-ef0b5-c147bbe98312.json') | |
admin.initializeApp({ credential: admin.credential.cert(serviceAccount) }) | |
const db = admin.firestore() | |
const taskDocRefs = db.collection('tasks').orderBy('difficulty') | |
taskDocRefs.get().then(data => { | |
const result = [] | |
data.docs.forEach(doc => { | |
result.push(doc.data()) | |
}) | |
fs.writeFile('./backup.json', JSON.stringify(result), err => { | |
if (err) { | |
console.log(`BACKUP ERROR WITH MESSAGE ${err}`) | |
} | |
console.log('BACKUP SUCCESSFULLY') | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment