无法读取 firestore 运行时未定义的属性'toString'



我想通过每天安排一次来"导出消防仓库数据"。这是燃烧基地的官方文件。我试过了,但没有工作,因为下面的错误:

无法读取未定义的属性"toString">

代码:

const functions = require('firebase-functions')
const firestoreClient = require('@google-cloud/firestore')
const admin = require('firebase-admin')
admin.initializeApp()
const firestore = admin.firestore()
//------------------------------------------------------
// backup
//------------------------------------------------------
const client = new firestoreClient.v1.FirestoreAdminClient()
exports.scheduledFirestoreExport = functions.pubsub
.schedule('every 24 hours')
.onRun(() => {
const databaseName = client.databasePath(
process.env.GCP_PROJECT,
'(default)',
)
const bucket = 'gs://backups-firestore'
return client
.exportDocuments({
name: databaseName,
outputUriPrefix: bucket,
collectionIds: [
'users',
],
})
.then((responses) => {
const response = responses[0]
console.log(`Operation Name: ${response['name']}`)
return response
})
.catch((err) => {
console.error(err)
throw new Error('Export operation failed')
})
})

如果process.env.GCP_PROJECT未定义,则会收到此错误消息。process.env.GCP_PROJECT在Node.js 10中未定义,而它在Node.js8中工作。

如果你这样做,它应该工作:

const projectId = process.env.GCP_PROJECT || process.env.GCLOUD_PROJECT;
const databaseName = client.databasePath(
projectId,
'(default)',
)

最新更新