[[["わかりやすい","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,["# Import from the source Mongo database\n=====================================\n\nThis page describes the first stage of the\n[migration process](/firestore/mongodb-compatibility/docs/migrate-data)\nwhere you use a Datastream stream to capture the contents of\nyour MongoDB-compatible source database and transfer them into a\nCloud Storage bucket.\n\nCreate YAML configuration files for the stream\n----------------------------------------------\n\nIn addition to usual command-line flags, creating a stream requires two\nconfiguration files in the YAML format:\n\n- The `mongo_source_config.yaml` file configures the selection of specific\n resources for migration, such as the database name. Mongo connectivity\n parameters such as the hostname, username, and password are all properties\n of the connection profile. However, the database (and any specific\n collections within that database) are a property of the stream.\n\n- The `gcs_dst_config.yaml` file configures the data placement within\n Cloud Storage. The Cloud Storage bucket and the root\n path within the bucket are properties of the connection profile. However,\n the data format and the data placement within the Cloud Storage\n bucket structure are a property of the stream.\n\nThe following command examples create these files and populate them with values\nfrom the\n[environment variables](/firestore/mongodb-compatibility/docs/migrate-configure-env-vars)\nthat you've set earlier. As an alternative, you can create these files in any\ntext editor and substitute the values manually. \n\n echo \"$(cat \u003c\u003cEOF\n includeObjects:\n databases:\n - database: ${MONGODB_DATABASE_NAME}\n EOF\n )\" \u003e mongo_source_config.yaml\n\n echo \"$(cat \u003c\u003cEOF\n path: \"/${GCS_BUCKET_SUB_PATH}\"\n avroFileFormat: {}\n EOF\n )\" \u003e gcs_dst_config.yaml\n\nThe previous example configures the full contents of $MONGODB_DATABASE_NAME for\nmigration. It is also possible to limit the migration to specific collections\nwithin the database. For example, to migrate only the collections `users` and\n`chats` use the following: \n\n includeObjects:\n databases:\n - database: ${MONGODB_DATABASE_NAME}\n collections:\n - collection: users\n - collection: chats\n\nCreate a Datastream stream\n--------------------------\n\nNext, create a stream that connects the source and the destination: \n\n gcloud datastream streams create \"$DATASTREAM_NAME\" \\\n --display-name=\"$DATASTREAM_NAME\" \\\n --location=\"$LOCATION\" \\\n --source=\"$SRC_CONNECTION_PROFILE_NAME\" \\\n --destination=\"$DST_CONNECTION_PROFILE_NAME\" \\\n --mongodb-source-config=./mongo_source_config.yaml \\\n --gcs-destination-config=./gcs_dst_config.yaml \\\n --backfill-all\n\nFor more information about monitoring the Datastream stream\ncreation, see\n[Troubleshooting](/firestore/mongodb-compatibility/docs/migrate-troubleshooting).\n\nActivate the Datastream stream\n------------------------------\n\nFinally, activate the new stream.\n\nAs the stream begins pulling data and streaming changes from the Mongo source,\nyou can observe new directories and files created in the\nCloud Storage bucket, under the path configured in the connection\nprofile and the stream.\n| **Important:** At this point your MongoDB-compatible source database is **still the\n| source of truth** for your application workloads. The database must continue to receive queries and updates until the migration [reaches a specific milestone](/firestore/mongodb-compatibility/docs/migrate-traffic) described later.\n\nTo activate the stream, run the following command: \n\n gcloud datastream streams update \"$DATASTREAM_NAME\" \\\n --location=\"$LOCATION\" \\\n --state=RUNNING \\\n --update-mask=state\n\nWhat's next\n-----------\n\nProceed to\n[Write data into the destination database](/firestore/mongodb-compatibility/docs/migrate-write-to-destination)."]]