[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-09-04 UTC。"],[],[],null,["# Migrate traffic to Firestore\n============================\n\nThis page describes the last stage of the\n[migration process](/firestore/mongodb-compatibility/docs/migrate-data)\nwhere you monitor the migration and determine when to switch traffic to\nminimize the downtime of your application.\n| **Caution:** There are several critical steps in the migration process that must be orchestrated correctly **to ensure no data loss and minimize application\n| downtime**.\n\nThese steps are:\n\n1. Determine whether any errors were encountered during the data transfer. Note the current [known limitations](/firestore/mongodb-compatibility/docs/migrate-data#limitations) for data types and document sizes.\n2. Determine when it is appropriate to shut down write traffic to the source database.\n3. Determine when all the data (including recent change events) was replicated to the Firestore with MongoDB compatibility database. At this point, it is safe to redirect read traffic to the new destination.\n4. After all your application workloads are consistently reading data only from Firestore, it is then safe to enable and direct the write traffic to Firestore with MongoDB compatibility database.\n\nCheck for migration completion milestones\n-----------------------------------------\n\nThe instructions in this section require access to\nDataflow within the Google Cloud console.\n\nIn the Google Cloud console, go to the **Dataflow** page:\n\n[Go to Dataflow](https://console.cloud.google.com/dataflow/jobs)\n\n### Source database is receiving all read and write traffic\n\nAfter initiating both the Datastream and the\nDataflow pipelines, your source database should continue\nto receive both read and write traffic. You can use the following milestones to\ndetermine when the migration can proceed to the next step:\n\n- The **Transactional write events** step of the Dataflow\n pipeline is no longer processing a backlog of the data and the throughput\n drops to a low steady state that matches with your source database's active\n traffic:\n\n- The data freshness in the Datastream **Monitoring** tab is\n at a minimum and is very close behind the ongoing traffic in your source\n database:\n\nAfter the data transfer reaches this steady state, advance to the next step.\n\n### Shut down write traffic to the source database\n\n| **Caution:** This part of the procedure will require a short period of write unavailability.\n\nAfter you've determined that the Datastream stream have\ncompleted the bulk backfill, and the Dataflow template is\ndoing transactional write at a steady speed only for live changes of the source\ndatabase, you can begin the cutover process. This process will require a small\namount of downtime to allow for all remaining traffic to be replicated to the\ntarget Firestore with MongoDB compatibility database.\n\n1. Stop all write traffic to the MongoDB-compatible source database. Depending\n on your application requirements and functionality, you might want to\n continue to allow read traffic to the source database.\n\n2. Monitor the Datastream throughput and logs, and the\n Dataflow throughput, data lag, and logs to ensure the last\n of the write traffic was processed.\n\n | **Caution:** Wait at least 20 minutes to **ensure the last of the traffic is\n | fetched from the source database**.\n3. [Inspect the Dead Letter Queue](/firestore/mongodb-compatibility/docs/migrate-troubleshooting#non-retryable-errors).\n Determine if any documents couldn't be written to the destination database\n during the migration, and make a decision about whether to continue with\n the migration.\n\n### Migrate read traffic to Firestore\n\nAfter all pending change stream events are replicated to\nFirestore, both databases contain the exact same data. You can\nnow transfer the read traffic, and then the write traffic.\n\nIf you chose to allow read traffic to the MongoDB-compatible source database in\nthe previous step:\n\n1. Transfer the read traffic.\n2. Ensure that all services that were originally connected to the MongoDB-compatible source database were updated to perform reads from the Firestore with MongoDB compatibility database.\n\n### Migrate write traffic to Firestore\n\nAfter the previous step is completed, it is safe to redirect your application's\nwrite traffic directly to Firestore.\n\nStop the migration pipeline\n---------------------------\n\nThe migration is now complete. Your Datastream stream and the\nDataflow job can now be stopped.\n\nPause the Datastream stream: \n\n gcloud datastream streams update \"$DATASTREAM_NAME\" \\\n --location=\"$LOCATION\" \\\n --state=PAUSED \\\n --update-mask=state\n\n| **Note:** If required, you can [delete the stream](/datastream/docs/delete-a-stream) after the migration completes.\n\nTo shut down the Dataflow pipeline:\n\n1. Listing all current jobs:\n\n gcloud dataflow jobs list --region=\"$LOCATION\"\n\n The output will produce a list of Dataflow jobs.\n2. In the list of jobs, find the `NAME` value that has the timestamp that\n you've specified in the \u003cvar translate=\"no\"\u003eDATAFLOW_START_TIME\u003c/var\u003e\n [environment variable](/firestore/mongodb-compatibility/docs/migrate-configure-env-vars).\n\n Format: `dataflow-mongodb-to-firestore-`\u003cvar translate=\"no\"\u003eDATAFLOW_START_TIME\u003c/var\u003e.\n Example: `dataflow-mongodb-to-firestore-20250514173638`.\n3. Obtain the corresponding `JOB_ID`. Example:\n `2025-05-14_17_36_39-10772223470853954680`.\n\n4. Run the drain command for this job ID:\n\n gcloud dataflow jobs drain \\\n \u003cvar translate=\"no\"\u003eJOB_ID\u003c/var\u003e \\\n --region=\"$LOCATION\"\n\n Example: \n\n gcloud dataflow jobs drain \\\n 2025-05-14_17_36_39-10772223470853954680 \\\n --region=\"$LOCATION\"\n\nWhat's next\n-----------\n\nFor troubleshooting tips, check [Migration troubleshooting](/firestore/mongodb-compatibility/docs/migrate-troubleshooting)."]]