Skip to content

Instantly share code, notes, and snippets.

@iammarkps
Created October 13, 2019 14:25
Show Gist options
  • Save iammarkps/98de4da8abec93d2002ee82801c4c431 to your computer and use it in GitHub Desktop.
Save iammarkps/98de4da8abec93d2002ee82801c4c431 to your computer and use it in GitHub Desktop.
programming.in.th | Tasks Backup
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