Firebase-tools: Firestore 和数据库模拟器:使用数据集初始化实例

创建于 2019-03-12  ·  39评论  ·  资料来源: firebase/firebase-tools

如果能够使用数据集创建 Firestore 模拟器的实例,那就太好了。

目前,我们正在进行批量写入以初始化或重置模拟器的实例。 问题是更新 120 个操作(我们的测试数据集)需要近 3 秒。

是否可以从快照创建 Firestore 模拟器实例或提高模拟器的性能以进行大型更新?

emulator-suite database firestore feature request

最有用的评论

将数据导入 Firestore 模拟器(即使用“种子”数据对其进行初始化)的功能应该会在下一个版本中推出。 一开始会有点手动,我们将在后续版本中添加更好的工具。

研究实时数据库模拟器需要什么。

所有39条评论

我同意在初始化时加载数据库“快照”会很棒。 我目前在本地运行 firestore 和函数模拟器进行开发,但是当我用测试数据为数据库播种时,会执行一堆 firestore 函数触发器。 这是非常不受欢迎的,那么是否有任何计划帮助加载初始数据,或者更好的是将 Firestore 数据持久化到磁盘?

感谢您提出想要在没有函数的情况下播种数据的观点
射击。 作为权宜之计,我们绝对可以实施一种“转向
off" 函数在您加载数据时通过特殊调用触发。
也可能对某些测试有用。 你会用那个吗?

但从长远来看,我们需要导入/导出。

2019 年 10 月 12 日星期六上午 11:54 Wyatt Ades [email protected]写道:

我同意加载数据库“快照”会很棒
初始化。 我目前运行 firestore 和函数模拟器
在本地进行开发,但是当我用测试数据为数据库播种时,一堆
的 firestore 函数触发器被执行。 这是非常不可取的,所以
是否有任何帮助加载初始数据的功能的计划,或者,
更好的是,firestore 数据持久化到磁盘?


您收到此消息是因为您订阅了此线程。
直接回复本邮件,在GitHub上查看
https://github.com/firebase/firebase-tools/issues/1167?email_source=notifications&email_token=ACATB2VEE7BBI75HECFTE23QOIMOLA5CNFSM4G5NG5X2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBCGBZA#issuecomment-541352164
或取消订阅
https://github.com/notifications/unsubscribe-auth/ACATB2WHUTO43JISN54J4U3QOIMOLANCNFSM4G5NG5XQ
.

是的,现在这将是一个很好的解决方案,谢谢!

所以还没有为此设定里程碑? 但是我现在喜欢这支球队的一件事,它似乎更加活跃和反应迅速。

伙计们能否在此范围内添加实时数据库以及 firestore 数据库。

@anantanandgupta 还没有里程碑,但是是的,我们尝试对取得的进展保持开放态度! 而且我还添加了数据库模拟器。 对于数据库,问题更简单(JSON 格式),但我们仍然需要帮助您“暂停”云函数

我知道我很好。 但要告诉你关键是,我完全围绕 firebase 设计了这个巨大的平台,每个人都反对这个,但我的努力已经证明,我决定使用 firebase 作为技术并没有错。 在这一点上,它已经变得如此之大,以至于多个开发人员使用托管在云上的公共数据库来处理多个功能已变得不可能。 因此,如果我们每个人都可以在数据库的本地副本上工作,那将会更加容易和高效。

将数据导入 Firestore 模拟器(即使用“种子”数据对其进行初始化)的功能应该会在下一个版本中推出。 一开始会有点手动,我们将在后续版本中添加更好的工具。

研究实时数据库模拟器需要什么。

@ryanpbrewster有没有关于如何设置“种子”数据的文档?

@SamyPesse这已在 Emulator JAR 本身内部实现(如@ryanpbrewster所说),但我们实际上并没有通过firebase-tools公开 API 来进行导入,因此这并不是您真正可以使用的东西。

您介意分享一下您希望它如何工作吗? 你会喜欢上的标志firebase命令,在一个领域firebase.json或其他什么东西?

导入和导出数据目前已实现,但我们还没有弄清楚如何轻松使用这些功能。 所以请记住,我们知道这些说明很粗略,我们乐于接受有关如何改进这一点的想法:

获得出口

您可以从生产 Firestore 实例或本地模拟器生成导出。

模拟器导出

启动模拟器并用你想要的数据填充它。 一旦您的数据库处于您喜欢的状态,请创建一个导出:

curl "localhost:8080/emulator/v1/projects/ryanpbrewster-test:export" \
  -d '{"database": "projects/ryanpbrewster-test/databases/(default)","export_directory":"."}' \
  -H "Content-Type: application/json

这会将导出转储到本地文件系统中的firestore_export_1576524691/

生产出口

您需要一个 Google Cloud Storage 存储分区。 我将使用我的测试项目的默认 AppEngine 存储桶ryanpbrewster-test.appspot.com 。 跑

gcloud firestore export gs://ryanpbrewster-test.appspot.com/firestore-export

Firestore 会将您的生产数据的完整副本转储到 Google Cloud Storage。 如果您愿意,可以使用--collection-ids标志将导出限制为一组特定的集合。

完成后,您可以将其复制到本地文件系统(请注意,如果您有一个庞大的数据库,这会很糟糕):

gsutil cp -r gs://ryanpbrewster-test.appspot.com/firestore-export .

导入数据

目前,将数据导入模拟器的唯一方法是通过命令行标志:

java -jar ~/.cache/firebase/emulators/cloud-firestore-emulator-v1.10.2.jar \
  --seed_from_export=firestore_export_1576524691/firestore_export_1576524691.overall_export_metadata

如果一切顺利,模拟器将启动并包含您的所有数据。

请注意,它期望的路径是.overall_export_metadata文件的位置,该文​​件应位于导出目录的顶层。

我能够从导出中模拟 Firestore 数据。 现在,如果我尝试启动 firebase 模拟器套装。 Firestore 模拟器无法运行,因为模拟器已在端口中运行。 我什至尝试设置无法识别的 FIRESTORE_EMULATOR_HOST 变量。 如果种子路径也可以在启动模拟器时沿着命令传递,它将更有帮助并减少大量开发时间,如firebase emulators:start --firestore_seed_from_export = \path\to\seed\file

+1 @prgwar的建议。 如何使用此启动 Firestore 运行模拟器套件? 模拟器中的函数使用生产,因为“⚠ 函数:Cloud Firestore 模拟器未运行,因此调用 Firestore 会影响生产。”

@prgwar感谢您的建议,我们目前正在确定用于从firebase命令指定导入/导出的 API。 直接使用jar只是一种解决方法,而不是我们实际希望开发人员长期做的事情。

@srolfe26您的问题听起来firebase init emulators以初始化 Firestore 模拟器,然后再次运行firebase emulators:start

对于任何其他 WSL(1 或 2)用户,您可能无法从浏览器连接到模拟器。 我在上面的命令中添加了一个--host 0.0.0.0标志并解决了这个问题。

java -jar ~/.cache/firebase/emulators/cloud-firestore-emulator-v1.10.2.jar \
  --seed_from_export=firestore_export_1576524691/firestore_export_1576524691.overall_export_metadata \
  --host 0.0.0.0

@prgwar 是否建议使用 --firestore_seed_from_export=可以接受吗?

如果是这样,我愿意提出 PR。 我还能如何帮助让球滚动?

如果可以在实时数据库模拟器上实现相同的 seed_from_export 功能,我也很高兴。

@spencerwhyte感谢您的报价! 我现在正在积极解决这个问题,致力于支持 Firestore 和 RTDB 以及任何未来的模拟器。

您如何看待这种一般流程:

  • “备份”是一个包含以下内容的文件夹:

    • 一堆规范格式的独立模拟器备份

    • 描述它们的单个metadata.json文件

  • 要使用种子启动模拟器,请执行以下操作: firebase emulators:start --import="./folder-with-backup"
  • 要备份正在运行的模拟器,您可以在它们运行时打开一个新终端并执行firebase emulators:export

这就是我目前正在做的事情,我认为这是最灵活的事情,但我非常愿意接受反馈

@samtstern

这个设计听起来很完美,只要我们可以使用模拟器导出格式/备份格式。 如果它与生产备份的格式相同,那就行了。 我们需要在不触发触发器的情况下为集成测试导入大量数据。 目前,我们通过在测试时禁用触发器的一些检查来幸存下来,但是我们很想避免这种复杂性。 这种对--import支持将使我们能够简化事情。

我们使用firebase emulators:exec进行测试,所以只要它也适用于exec ,我们就会很高兴。

@斯宾塞怀特

1) 是的,我们肯定会尽可能坚持与制作相同的格式。 因此,对于 Firestore,我们将支持导入/导出格式,对于 RTDB,它将只是一个巨大的json文件。
2) 是的,我们将支持emulators:exec --import

感谢您的反馈!

PR #1968 实现了此功能(目前仅适用于 Firestore,实时数据库即将推出)并将包含在下一个 CLI 版本中(可能7.14.0

此功能刚刚在7.14.0 ...尝试一下,让我们知道您的想法! 现在它只是 Firestore,但接下来是实时数据库。

这在任何地方都有记录吗? 另外,有没有办法在没有 Google Cloud Storage 存储桶(我没有)的情况下导出生产数据?
在没有从云数据存储中复制数据的情况下,很难在本地测试触发器。

@shaimo抱歉,我们在文档方面有点落后,但它们应该会在接下来的几天内发布!

要从生产中导出,您确实需要一个 Cloud Storage 存储分区。 这是因为导出是一个“托管”操作,这意味着它发生在某个 Google 服务器上。 我们无法对您的本地文件系统运行这样的操作,我们需要一个云目标。

如果您有一个 Firebase 项目,您实际上有一个可以使用的默认 Cloud Storage 存储桶,其中包含一些免费配额。 只需导航到 Firebase 控制台的存储部分即可查看。

@samtstern由于文档可能需要一些时间,您能否简要介绍一下如何导入/导出到模拟器实例?

我们现在有一些关于新标志的文档:
https://firebase.google.com/docs/emulator-suite/install_and_configure#startup

但无论如何,让我给你举个例子。 要使用导入/导出,您需要两个终端窗口,所以我们称它们为终端 1终端 2

首先启动模拟器

1号航站楼

$ firebase emulators:start
# ...

在其中建立了一些要保存的数据后,在另一个终端中运行 export 命令:

2 号航站楼

$ firebase emulators:export ./mydirectory
# ...

现在您在./mydirectory有一个导出。 下次启动模拟器时,告诉他们从那里导入:

1号航站楼

$ firebase emulators:start --import=./mydirectory
# ...

就是这样!

@samtstern我们可以使用 firebase emulators:start --import 命令从生产导出中导入吗?
我看到emulator:start --import 正在寻找 firebase-export-metadata.json 但我有 firestore-export/firestore-export.overall_export_metadata

@landonj可以,但目前有点棘手。 最简单的做法是运行emulators:export一次,然后修改 JSON 文件以指向您的生产导出而不是本地导出。

有什么关于为模拟器播种 RTDB 的吗?

@FergyKay什么都没有,但你可以在这里关注:
https://github.com/firebase/firebase-tools/issues/2079

这是非常需要的

我正在尝试做与@landonj完全相同的事情..

我尝试了@samtstern所说的......但我收到了一个错误......

我做错了什么?

bdw .. 文件存在!

firebase emulators:start --debug --only firestore,functions --import=/Users/ridermansb/Projects/meve.ai/backups/emulator-data

[2020-05-31T13:31:23.601Z] com.google.cloud.datastore.core.exception.DatastoreException:无法解析整体导出元数据文件
在 com.google.cloud.datastore.emulator.impl.ExportImportUtil.parseOverallMetadataFile(ExportImportUtil.java:225)
在 com.google.cloud.datastore.emulator.impl.ExportImportUtil.fetchEntities(ExportImportUtil.java:54)
在 com.google.cloud.datastore.emulator.firestore.CloudFirestore.main(CloudFirestore.java:89)
{"metadata":{"emulator":{"name":"firestore"},"message":"com.google.cloud.datastore.core.exception.DatastoreException: 无法解析整体导出元数据文件\n\tat com.google.cloud.datastore.emulator.impl.ExportImportUtil.parseOverallMetadataFile(ExportImportUtil.java:225)\n\tat com.google.cloud.datastore.emulator.impl.ExportImportUtil.fetchEntities(ExportImportUtil.java:54)\n \tat com.google.cloud.datastore.emulator.firestore.CloudFirestore.main(CloudFirestore.java:89)\n"}}
[2020-05-31T13:31:23.602Z] 由:java.io.FileNotFoundException: /Users/ridermansb/Projects/meve.ai/backups/emulator-data/Users/ridermansb/Projects/meve.ai/backups/ 2020-05-31/2020-05-31/2020-05-31T13:19:28_6168.overall_export_metadata(没有这样的文件或目录)
{"metadata":{"emulator":{"name":"firestore"},"message":"Caused by: java.io.FileNotFoundException: /Users/ridermansb/Projects/meve.ai/backups/emulator-data /Users/ridermansb/Projects/meve.ai/backups/2020-05-31/2020-05-31/2020-05-31T13:19:28_6168.overall_export_metadata(没有那个文件或目录)\n"}}
[2020-05-31T13:31:23.603Z] 在 java.base/java.io.FileInputStream.open0(本机方法)
在 java.base/java.io.FileInputStream.open(FileInputStream.java:213)
在 java.base/java.io.FileInputStream。(FileInputStream.java:155)
在 com.google.cloud.datastore.emulator.impl.ExportImportUtil.parseOverallMetadataFile(ExportImportUtil.java:215)
... 2 更多
{"metadata":{"emulator":{"name":"firestore"},"message":"\tat java.base/java.io.FileInputStream.open0(Native Method)\n\tat java.base/ java.io.FileInputStream.open(FileInputStream.java:213)\n\tat java.base/java.io.FileInputStream.(FileInputStream.java:155)\n\tat com.google.cloud.datastore.emulator.impl.ExportImportUtil.parseOverallMetadataFile(ExportImportUtil.java:215)\n\t... 2 更多\n"}}

错误:firestore:Firestore 模拟器已退出,代码:1

@landonj可以,但目前有点棘手。 最简单的做法是运行emulators:export一次,然后修改 JSON 文件以指向您的生产导出而不是本地导出。

你能扩展一下吗? 我可以直接指向 gcloud 存储桶吗? 还是必须先在本地下载导出的内容? 我需要修改哪些文件?

以下是我尝试过的:

> firebase emulators:start
> firebase emulators:export ~/emulator-data/
> # close the emulator
> gcloud firestore export gs://xxxxx-xxxxx-xxxxx/emulator/
> gsutil cp -r gs://xxxxx-xxxxx-xxxxx/emulator ~/emulator-data/
> firebase emulators:start --only firestore --import /home/gugahoi/emulator-data/emulator/ --debug
[2020-06-01T10:04:36.492Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[2020-06-01T10:04:36.493Z] > authorizing via signed-in user
i  emulators: Starting emulators: firestore {"metadata":{"emulator":{"name":"hub"},"message":"Starting emulators: firestore"}}
[2020-06-01T10:04:36.510Z] [hub] writing locator at /tmp/hub-flux-development.json
i  emulators: Shutting down emulators. {"metadata":{"emulator":{"name":"hub"},"message":"Shutting down emulators."}}
i  hub: Stopping emulator hub {"metadata":{"emulator":{"name":"hub"},"message":"Stopping emulator hub"}}
[2020-06-01T10:04:36.825Z] Error: ENOENT: no such file or directory, open '/home/gugahoi/emulator-data/emulator/firebase-export-metadata.json'
    at Object.openSync (fs.js:458:3)
    at Object.readFileSync (fs.js:360:35)
    at Object.<anonymous> (/home/gugahoi/.nvm/versions/node/v12.16.3/lib/node_modules/firebase-tools/lib/emulator/controller.js:183:44)
    at Generator.next (<anonymous>)
    at fulfilled (/home/gugahoi/.nvm/versions/node/v12.16.3/lib/node_modules/firebase-tools/lib/emulator/controller.js:5:58)
    at processTicksAndRejections (internal/process/task_queues.js:97:5)

Error: An unexpected error has occurred.

由于上述内容似乎不起作用,我使用以下内容更新了firebase-exports-metadata.json文件:

> cat firebase-export-metadata.json
{"version":"8.4.1","firestore":{"version":"1.11.4","path":"emulator","metadata_file":"emulator/emulator.overall_export_metadata"}}

下面是目录结构:

gugahoi:~/emulator-data > tree .
.
├── emulator
│   ├── all_namespaces
│   │   └── all_kinds
│   │       ├── all_namespaces_all_kinds.export_metadata
│   │       ├── output-0
│   │       └── output-1
│   └── emulator.overall_export_metadata
├── firebase-export-metadata.json
├── firebase-export-metadata.json.bak
└── firestore_export
    └── firestore_export.overall_export_metadata

但是我在模拟器 UI 中仍然没有数据。

编辑

只是想我会添加模拟器的最终输出,它运行没有错误但没有我的数据:

> firebase emulators:start --only firestore --import /home/gugahoi/emulator-data/ --debug
[2020-06-01T11:31:34.256Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[2020-06-01T11:31:34.257Z] > authorizing via signed-in user
i  emulators: Starting emulators: firestore {"metadata":{"emulator":{"name":"hub"},"message":"Starting emulators: firestore"}}
[2020-06-01T11:31:34.274Z] [hub] writing locator at /tmp/hub-flux-development.json
i  firestore: Importing data from /home/gugahoi/emulator-data/emulator/emulator.overall_export_metadata {"metadata":{"emulator":{"name":"firestore"},"message":"Importing data from /home/gugahoi/emulator-data/emulator/emulator.overall_export_metadata"}}
[2020-06-01T11:31:34.302Z] Ignoring unsupported arg: projectId {"metadata":{"emulator":{"name":"firestore"},"message":"Ignoring unsupported arg: projectId"}}
[2020-06-01T11:31:34.303Z] Ignoring unsupported arg: auto_download {"metadata":{"emulator":{"name":"firestore"},"message":"Ignoring unsupported arg: auto_download"}}
[2020-06-01T11:31:34.303Z] Starting Firestore Emulator with command {"binary":"java","args":["-Duser.language=en","-jar","/home/gugahoi/.cache/firebase/emulators/cloud-firestore-emulator-v1.11.4.jar","--host","localhost","--port",8080,"--seed_from_export","/home/gugahoi/emulator-data/emulator/emulator.overall_export_metadata","--rules","/home/gugahoi/projects/flux/flux/firestore.rules"],"optionalArgs":["port","webchannel_port","host","rules","functions_emulator","seed_from_export"],"joinArgs":false} {"metadata":{"emulator":{"name":"firestore"},"message":"Starting Firestore Emulator with command {\"binary\":\"java\",\"args\":[\"-Duser.language=en\",\"-jar\",\"/home/gugahoi/.cache/firebase/emulators/cloud-firestore-emulator-v1.11.4.jar\",\"--host\",\"localhost\",\"--port\",8080,\"--seed_from_export\",\"/home/gugahoi/emulator-data/emulator/emulator.overall_export_metadata\",\"--rules\",\"/home/gugahoi/projects/flux/flux/firestore.rules\"],\"optionalArgs\":[\"port\",\"webchannel_port\",\"host\",\"rules\",\"functions_emulator\",\"seed_from_export\"],\"joinArgs\":false}"}}
i  firestore: Firestore Emulator logging to firestore-debug.log {"metadata":{"emulator":{"name":"firestore"},"message":"Firestore Emulator logging to \u001b[1mfirestore-debug.log\u001b[22m"}}
[2020-06-01T11:31:35.197Z] API endpoint: http://localhost:8080
 {"metadata":{"emulator":{"name":"firestore"},"message":"API endpoint: http://localhost:8080\n"}}
[2020-06-01T11:31:35.198Z] If you are using a library that supports the FIRESTORE_EMULATOR_HOST environment variable, run:

   export FIRESTORE_EMULATOR_HOST=localhost:8080

Dev App Server is now running.

 {"metadata":{"emulator":{"name":"firestore"},"message":"If you are using a library that supports the FIRESTORE_EMULATOR_HOST environment variable, run:\n\n   export FIRESTORE_EMULATOR_HOST=localhost:8080\n\nDev App Server is now running.\n\n"}}
[2020-06-01T11:31:35.322Z] Ignoring unsupported arg: auto_download {"metadata":{"emulator":{"name":"ui"},"message":"Ignoring unsupported arg: auto_download"}}
[2020-06-01T11:31:35.322Z] Ignoring unsupported arg: port {"metadata":{"emulator":{"name":"ui"},"message":"Ignoring unsupported arg: port"}}
[2020-06-01T11:31:35.323Z] Starting Emulator UI with command {"binary":"node","args":["/home/gugahoi/.cache/firebase/emulators/ui-v1.0.0/server.bundle.js"],"optionalArgs":[],"joinArgs":false} {"metadata":{"emulator":{"name":"ui"},"message":"Starting Emulator UI with command {\"binary\":\"node\",\"args\":[\"/home/gugahoi/.cache/firebase/emulators/ui-v1.0.0/server.bundle.js\"],\"optionalArgs\":[],\"joinArgs\":false}"}}
i  ui: Emulator UI logging to ui-debug.log {"metadata":{"emulator":{"name":"ui"},"message":"Emulator UI logging to \u001b[1mui-debug.log\u001b[22m"}}
[2020-06-01T11:31:35.395Z] Web / API server started at http://localhost:4000
 {"metadata":{"emulator":{"name":"ui"},"message":"Web / API server started at http://localhost:4000\n"}}

┌───────────────────────────────────────────────────────────────────────┐
│ ✔  All emulators ready! View status and logs at http://localhost:4000 │
└───────────────────────────────────────────────────────────────────────┘

┌───────────┬────────────────┬─────────────────────────────────┐
│ Emulator  │ Host:Port      │ View in Emulator UI             │
├───────────┼────────────────┼─────────────────────────────────┤
│ Firestore │ localhost:8080 │ http://localhost:4000/firestore │
└───────────┴────────────────┴─────────────────────────────────┘
  Other reserved ports: 4400, 4500

Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.

@gugahoi你的帖子帮我想出了一个解决方案: https : //gist.github.com/bkuri/36cef71bcf30a5416b1c353cb81f38ed

这是一个小型 bash 脚本,可以为您的云存储模拟器实例提供种子。 它所需要的只是项目名称和保存导出数据的目标路径。 即: ./seed-storage.sh my-project /tmp/export

顺便说一句,上面的脚本取决于两个非常常用的工具( lsofscreen )除了通常的嫌疑人( firebasegcloudgsutil ),因此请确保已安装它们。

希望这有助于某人。 :+1:

无论如何要避免在导入现有数据库时触发 Firestore 功能?

@bkuri感谢您提供该脚本,我想我的设置/安装有些奇怪,因为我仍然无法在 firestore 模拟器控制台中显示任何数据。

感谢@gugahoi,我能够将生产中的集合导入本地模拟器。
为此,我执行了以下步骤:

  1. 转到我本地的 Firebase 项目路径。
  2. 使用以下命令启动模拟器: firebase emulators:start
  3. 使用http://localhost :4000/firestore 上的 GUI 手动创建一些模型数据,使用提供的按钮:_+ 开始收集_和 _+ 添加文档_。
  4. 使用以下方法在本地导出此数据: emulators:export ./mydirectory
  5. 关于位于 _Firebase Database / Cloud Firestore_ 的项目数据,我导出了一个这样的集合: gcloud firestore export gs://my-project-bucket-id.appspot.com --collection-ids=myCollection导出现在位于 _Firebase Storage_ 下一个以时间戳为名称的文件夹中(我没有使用前缀用于我的测试)
  6. 将此文件夹下载到本地驱动器: gsutil cp -r gs://my-project-bucket-id.appspot.com/myCollection ./production_data_export注意:我在 Windows 环境中执行此操作... _gsutil_ 将抛出此错误:_"OSError: 文件名、目录名或卷标语法不正确"_如果文件夹在 Windows 中的文件夹名称包含无效字符(即冒号)或此错误:_"OSError: Invalid argument.9.0 B]"_ 如果文件夹中的内部文件也包含无效字符。 为了能够在本地下载导出,请使用有效的 Windows 名称(即删除冒号)重命名它们,如下所示: gsutil mv gs://my-project-bucket-id.appspot.com/2020-05-22T02:01:06_86152 gs://my-project-bucket-id.appspot.com/myCollection
  7. 下载后,模仿本地导出结构,将文件夹重命名为firestore_export并从本地导出文件夹复制firebase-export-metadata.json文件。 只是为了直观,这是我得到的结构:
$ tree .
.
├── local_data_export
│   ├── firebase-export-metadata.json
│   └── firestore_export
│       ├── all_namespaces
│       │   └── all_kinds
│       │       ├── all_namespaces_all_kinds.export_metadata
│       │       └── output-0
│       └── firestore_export.overall_export_metadata
└── production_data_export
    ├── firebase-export-metadata.json
    └── firestore_export
        ├── all_namespaces
        │   └── kind_myCollection
        │       ├── all_namespaces_kind_myCollection.export_metadata
        │       ├── output-0
        │       └── output-1
        └── firestore_export.overall_export_metadata

8 directories, 9 files
  1. 最后启动本地模拟器指向这个要导入的生产数据: firebase emulators:start --import=./mock_up_data/production_data_export/
  2. 您应该在以下位置看到导入的数据: http://localhost :4000/firestore/

我希望这些说明足够清楚以提供帮助。 我希望这会在我们等待 Firebase 人员提供更强大的解决方案时对某人有所帮助。

作为一个简短的更新:当我发布上面评论中的说明时,我是在 WSL2 中进行的,它们似乎不起作用,但 Ubuntu 中的相同步骤似乎没问题。我怀疑 WSL2 中可能存在干扰.

我想以相反的方式执行此操作,我想将我的模拟器数据导入到生产中,我需要将 7000 个谷歌工作表行添加到我的 Firestore 中,我可以通过编辑一个函数来做到这一点,但是当我尝试在生产中执行此操作时,我的当函数内部出现问题时,也会超出内存限制,我最终可能会得到重复的数据。 我注意到导出导入,我注意到我可以导出我的本地模拟器 firestore 数据。 但是如何将我的本地备份导入到生产环境中呢?

@nvanhoesel导入/导出格式在生产环境和模拟器中是相同的。 但您的用例并不常见,因此您需要自己做一些工作才能将模拟器导出到 Google Cloud Storage,以便 Firestore 可以正确导入它。

此页面是否有帮助?
0 / 5 - 0 等级