Created
June 23, 2021 21:05
-
-
Save stargazing-dino/eb9fca2ecabdf7d71c4f110e09edb358 to your computer and use it in GitHub Desktop.
Copy questions
This file contains hidden or 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
import admin = require('firebase-admin'); | |
const serviceAccount: { [key: string]: any } = require('../service_key.json'); | |
admin.initializeApp({ | |
credential: admin.credential.cert(serviceAccount), | |
databaseURL: 'https://remac-test-prep.firebaseio.com', | |
}); | |
const firestore = admin.firestore(); | |
const questionsCollection = firestore.collection('questions'); | |
const questionsCopyCollection = firestore.collection('questions_copy'); | |
questionsCollection.get().then(async (snapshot) => { | |
const batch = admin.firestore().batch(); | |
for (const questionDoc of snapshot.docs) { | |
const questionCopyDoc = questionsCopyCollection.doc(questionDoc.id); | |
const questionData = questionDoc.data(); | |
batch.set( | |
questionCopyDoc, | |
questionData | |
); | |
} | |
await batch.commit(); | |
}).catch(console.error); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment