Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Zu Firestore mit MongoDB-Kompatibilität migrieren
In dieser Anleitung wird Schritt für Schritt beschrieben, wie Sie Ihre MongoDB-kompatible Quelldatenbank mit minimalen Ausfallzeiten zu einer Firestore-Datenbank mit MongoDB-Kompatibilität migrieren.
Migrationsvorgang
Der Migrationsprozess umfasst die folgenden Phasen:
Vorbereitung: Sie erstellen Ressourcen, die für die Migration erforderlich sind, und richten Umgebungsvariablen ein, die zum Ausführen von Befehlen in späteren Phasen des Migrationsprozesses verwendet werden.
Aus der MongoDB-kompatiblen Quelldatenbank importieren: Sie verwenden den Datastream-Dienst, um den Inhalt Ihrer MongoDB-kompatiblen Quelldatenbank zu erfassen und in einen Cloud Storage-Bucket zu übertragen.
Daten in eine Firestore mit MongoDB-Kompatibilität-Datenbank schreiben: Sie verwenden den Dataflow-Dienst, um Daten aus dem Cloud Storage-Bucket in eine Firestore mit MongoDB-Kompatibilität-Datenbank zu übertragen.
Diese Dataflow-Pipeline wird gleichzeitig mit dem Datastream-Stream ausgeführt, der Daten aus der MongoDB-kompatiblen Quelldatenbank abruft.
Traffic zu Firestore migrieren: An der entsprechenden Stelle im Verfahren migrieren Sie den Lese- und Schreibtraffic Ihrer Anwendung zur Firestore-Datenbank mit MongoDB-Kompatibilität und beenden die Migrationspipeline.
Das folgende Diagramm fasst den Migrationsprozess zusammen:
Ihre MongoDB-kompatible Quelldatenbank bleibt während der Datenübertragung im Bereitstellungsstatus:
Beim Datastream-Prozess werden sowohl inaktive Daten als auch Änderungsereignisse erfasst.
Es wird eine kurze Zeit der teilweisen Nichtverfügbarkeit geben, in der Sie den Schreibtraffic für Ihre Quelldatenbank beenden müssen. Während dieses Zeitraums wird der Rest der Änderungsereignisse in Firestore repliziert.
Nach Abschluss der Replikation kann die Firestore-Datenbank mit MongoDB-Kompatibilität die neue „Source of Truth“ für Ihren Anwendungs-Workload werden. Der gesamte Lese- und Schreibtraffic kann an die neue Datenbank weitergeleitet werden.
Detaillierte Migrationsschritte
In diesem Abschnitt wird die Migration genauer beschrieben.
Mit dem Datastream-Dienst wird ein Stream zwischen einer Quelle und einem Ziel erstellt. In diesem Fall ist die Quelle Ihre aktuelle MongoDB-kompatible Bereitstellung und das Ziel Cloud Storage. Dieser Prozess umfasst die folgenden Schritte:
Stream überwachen: So können Sie wichtige Meilensteine im Migrationsprozess identifizieren und feststellen, ob während der Datenübertragung Fehler aufgetreten sind.
Beenden Sie den Schreibzugriff auf die Quelldatenbank, wenn dies angebracht ist. Nachdem alle Daten, einschließlich der letzten Änderungen, in die Firestore-Datenbank mit MongoDB-Kompatibilität repliziert wurden, leiten Sie den Lesetraffic an das neue Ziel um.
Schreibvorgänge für Ihre Firestore-Datenbank mit MongoDB-Kompatibilität aktivieren.
Codebeispiele
Die Codebeispiele in diesem Leitfaden sind so konzipiert, dass sie nacheinander ausgeführt werden. In diesem Leitfaden wird davon ausgegangen, dass Sie Ihre Umgebung konfigurieren, indem Sie alle Umgebungsvariablen im Voraus einrichten. Anschließend führen Sie die für die Migration erforderlichen Befehle aus, die die bereits konfigurierten Umgebungsvariablen verwenden. Wir empfehlen, diesen Ansatz zu verwenden. Da viele Befehle dieselben Umgebungsvariablen verwenden, können Sie das Risiko von Fehlern zwischen den verschiedenen Phasen des Migrationsprozesses verringern.
Alternativ können Sie die Variablen in den Befehlsbeispielen durch dieselben Werte ersetzen, die Sie für die entsprechenden Umgebungsvariablen festgelegt haben.
Wenn Ihre Daten nicht den Einschränkungen in den oben genannten Kategorien entsprechen:
Wir empfehlen, diese Bedingungen in Ihrem Dataset zu berücksichtigen, bevor Sie mit der Migration beginnen.
Wenn Sie ohne Änderungen fortfahren, können Dokumente, die von den Einschränkungen betroffen sind, nicht in Firestore geschrieben werden und werden aussortiert.
Sie können entscheiden, wie diese Dokumente behandelt werden müssen. Wenn sie in unterstützte Typen, Werte oder Größen konvertiert werden, können sie noch einmal verarbeitet werden.
Für Datastream gelten die folgenden Anforderungen:
Die von Datastream unterstützte Mindestversion von MongoDB ist 4.0. Für einige Nebenversionen gibt es unterstützte Mindestpatchversionen:
4.0.21
4.2.10
4.4.2
Ihr MongoDB-Cluster muss Änderungsstreams unterstützen. Ihre MongoDB-Bereitstellung muss als Replikatset oder fragmentierter Cluster konfiguriert sein, damit Change Streams aktiviert werden können.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 2025-09-04 (UTC)."],[],[],null,["# Migrate to Firestore with MongoDB compatibility\n===============================================\n\nThis guide takes you through the step-by-step process of migrating your\nMongoDB-compatible source database to a Firestore with MongoDB\ncompatibility database with minimal downtime.\n\nAbout the migration process\n---------------------------\n\nThe migration process has the following stages:\n\n1. **Preparation**: You create resources required for the migration and set up\n environment variables that will be used to run commands at later stages of\n the migration process.\n\n2. **Import from the MongoDB-compatible source database**: You use the\n Datastream service to capture the contents of your\n MongoDB-compatible source database and transfer them into a\n Cloud Storage bucket.\n\n3. **Write data to Firestore with MongoDB compatibility\n database**: You use the Dataflow\n service to transfer data from the Cloud Storage bucket into a\n Firestore with MongoDB compatibility database.\n\n This Dataflow pipeline will run concurrently with the\n Datastream stream that is pulling data from the\n MongoDB-compatible source database.\n4. **Migrate traffic to Firestore**: At the appropriate point\n in the procedure, you migrate your application read and write traffic to\n the Firestore with MongoDB compatibility database and stop\n the migration pipeline.\n\nThe following diagram summarizes the migration process:\n\nYour MongoDB-compatible source database remains in a serving state while the data transfer\ntakes place:\n\n- The Datastream process captures both data at rest and change events.\n- There will be a short period of partial unavailability when you have to shut\n down write traffic to your source database. During this period, the\n remainder of the change events is replicated to Firestore.\n\n- After the replication completes, the Firestore with MongoDB\n compatibility database can become the new source of truth for your\n application workload. All read and write traffic can be directed to the new\n database.\n\nDetailed migration steps\n------------------------\n\nThis section describes the migration in more detail.\n\nThe Datastream service creates a stream between a source and a\ndestination. In this case, the source is your current MongoDB-compatible\ndeployment, while the destination is Cloud Storage. This process has\nthe following steps:\n\n1. [Create a source Datastream connection profile](/firestore/mongodb-compatibility/docs/migrate-create-connection-profiles)\n for your Mongo source. Specific instructions depend on the type and the way\n your MongoDB-compatible source is deployed.\n\n2. [Create a Cloud Storage bucket](/firestore/mongodb-compatibility/docs/migrate-configure-resources#create-bucket)\n that will receive the data and the change events from your\n MongoDB-compatible source database.\n\n3. [Create a destination Datastream connection profile](/firestore/mongodb-compatibility/docs/migrate-create-connection-profiles#connection-profile-storage)\n that uses this Cloud Storage bucket.\n\n4. [Create and actuate a Datastream stream](/firestore/mongodb-compatibility/docs/migrate-import-from-source)\n that connects the source connection profile to the destination connection\n profile.\n\n5. [Initiate a Dataflow pipeline](/firestore/mongodb-compatibility/docs/migrate-write-to-destination) to begin injecting the\n captured data into your Firestore with MongoDB\n compatibility database.\n\n6. [Monitor the stream](/firestore/mongodb-compatibility/docs/migrate-traffic#migration-completion-milestones)\n to identify important milestones in the migration process to determine\n whether any errors were encountered during the data transfer.\n\n7. When it's appropriate,\n [shut down write traffic](/firestore/mongodb-compatibility/docs/migrate-traffic#shut-down-write-traffic)\n to the source database. After all data, including recent changes, was\n replicated to the Firestore with MongoDB compatibility\n database, redirect read traffic to the new destination.\n\n8. [Enable write traffic](/firestore/mongodb-compatibility/docs/migrate-traffic#migrate-write-traffic)\n to your Firestore with MongoDB compatibility database.\n\nAbout code examples\n-------------------\n\nCode examples in this guide are meant to be executed one after another. This\nguide assumes that you configure your environment by setting up all environment\nvariables beforehand. Afterwards, you execute commands required for the\nmigration that use the already configured environment variables. We recommend\nto use this approach. Because many commands use same environment variables, you\ncan reduce the chance of introducing errors between different stages of the\nmigration process.\n\nAs an alternative, you can replace the variables in command examples with the\nsame values that you set for corresponding environment variables.\n\nLimitations\n-----------\n\nFirestore with MongoDB compatibility has the following limitations:\n\n- Firestore doesn't support the following BSON types:\n\n - Undefined\n - DBPointer\n - JavaScript\n - Symbol\n- Firestore has the following restrictions on the `_id` field:\n\n - ObjectIDs, Longs, and Strings in the document `_id` field are supported.\n - 0L as `_id` is not supported.\n- Firestore has a 4MB document size limit.\n\nIf any of your data contains the listed conditions:\n\n- We recommend to address these conditions in your dataset before starting the\n migration process.\n\n- If you choose to proceed without changes, then documents that are affected by\n the limitations will fail writing to Firestore and will be\n sidelined.\n You can decide on how these documents must be handled. If they are\n converted to supported types, values, or sizes, they can be reprocessed.\n\nDatastream has the following requirements:\n\n- The minimum major version of MongoDB supported by\n Datastream is 4.0. For some minor versions, there are\n minimum patch versions that are supported:\n\n - 4.0.21\n - 4.2.10\n - 4.4.2\n- Your MongoDB cluster must support Change Streams. Your MongoDB deployment\n must be configured as a\n [replica set](https://www.mongodb.com/docs/manual/replication/) or a\n [sharded cluster](https://www.mongodb.com/docs/manual/sharding/) for Change\n Streams to be enabled.\n\nWhat's next\n-----------\n\nProceed to\n[Configure resources for migration](/firestore/mongodb-compatibility/docs/migrate-configure-resources)."]]