对带有时间戳格式ID的文档进行Firestore备份

时间:2018-10-19 18:24:09

标签: google-cloud-firestore

我有一个Firestore数据库,我尝试备份它。

我尝试使用firestore-backupfirestore-backup-restore

但是它不起作用,因为在一个集合中,我使用带有时间戳ID的文档(采用以下格式:2018-10-19T12:30:40.066Z)。其他集合可以备份。

我收到此消息:

The behavior for Date objects stored in Firestore is going to change AND YOUR APP MAY BREAK.
To hide this warning and ensure your app does not break, you need to add the following code to your app before calling any other Cloud Firestore methods:
   const firestore = new Firestore();
   const settings = {/* your settings... */ timestampsInSnapshots: true};
   firestore.settings(settings);
With this change, timestamps stored in Cloud Firestore will be read back as Firebase Timestamp objects instead of as system Date objects.
So you will also need to update code expecting a Date to instead expect a Timestamp. For example:
// Old:
  const date = snapshot.get('created_at');
// New:
  const timestamp = snapshot.get('created_at');
  const date = timestamp.toDate();
Please audit all existing usages of Date when you enable the new behavior.
In a future release, the behavior will change to the new behavior, so if you do not follow these steps, YOUR APP MAY BREAK.
Backing up Document '/ttt/2018-10-19T12:30:40066Z'
(node:36336) UnhandledPromiseRejectionWarning: Error: Unable to create backup path for Document '2018-10-19T12:30:40066Z': RangeError: Maximum call stack size exceeded
    at FirestoreBackup.backupDocument (C:\Users\MD\AppData\Roaming\npm\node_modules\firestore-backup\dist\firestore.js:228:15)
    at C:\Users\MD\AppData\Roaming\npm\node_modules\firestore-backup\dist\firestore.js:210:25
    at C:\Users\MD\AppData\Roaming\npm\node_modules\firestore-backup\dist\utility.js:36:14
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
(node:36336) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:36336) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

那么,是否可以使用时间戳格式的ID备份Firebase集合?

2 个答案:

答案 0 :(得分:0)

Cloud Firestore具有官方支持的数据导出功能,请参见export and import data

下面是一个示例,显示了如何按计划运行导出操作:https://firebase.google.com/docs/firestore/solutions/schedule-export

答案 1 :(得分:0)

最后,我将时间戳ID更改为自定义格式(2018-10-19T12-30-40-066Z,将-和。替换为-)。

此自定义格式与备份兼容。