Skip to content

Instantly share code, notes, and snippets.

@Andrew7234
Last active October 17, 2022 20:56
Show Gist options
  • Save Andrew7234/c97d1ba7f70e82a24cdefbd26ba007d8 to your computer and use it in GitHub Desktop.
Save Andrew7234/c97d1ba7f70e82a24cdefbd26ba007d8 to your computer and use it in GitHub Desktop.
const firestore = require('@google-cloud/firestore');
const client = new firestore.v1.FirestoreAdminClient();
// Replace BUCKET_NAME
const bucket = 'gs://prod_dcd_backups'
exports.scheduledFirestoreExport = (event, context) => {
const databaseName = client.databasePath(
'oasis-infra-external-mpc4f-dcd',
'(default)'
);
return client
.exportDocuments({
name: databaseName,
outputUriPrefix: bucket,
// Leave collectionIds empty to export all collections
// or define a list of collection IDs:
// collectionIds: ['users', 'posts']
collectionIds: ['prod_dcd_survey_results_dc0'],
})
.then(responses => {
const response = responses[0];
console.log(`Operation Name: ${response['name']}`);
return response;
})
.catch(err => {
console.error(err);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment