이 페이지에서는 Datastream 스트림을 사용하여 MongoDB 호환 소스 데이터베이스의 콘텐츠를 캡처하고 Cloud Storage 버킷으로 전송하는 마이그레이션 프로세스의 첫 번째 단계를 설명합니다.
스트림의 YAML 구성 파일 만들기
스트림을 만들려면 일반적인 명령줄 플래그 외에도 YAML 형식의 구성 파일 두 개가 필요합니다.
mongo_source_config.yaml 파일은 데이터베이스 이름과 같은 마이그레이션할 특정 리소스의 선택을 구성합니다. 호스트 이름, 사용자 이름, 비밀번호와 같은 Mongo 연결 매개변수는 모두 연결 프로필의 속성입니다. 하지만 데이터베이스 (및 해당 데이터베이스 내의 특정 컬렉션)는 스트림의 속성입니다.
gcs_dst_config.yaml 파일은 Cloud Storage 내의 데이터 배치를 구성합니다. Cloud Storage 버킷과 버킷 내의 루트 경로는 연결 프로필의 속성입니다. 하지만 데이터 형식과 Cloud Storage 버킷 구조 내의 데이터 배치 방식은 스트림의 속성입니다.
다음 명령 예시에서는 이러한 파일을 만들고 이전에 설정한 환경 변수의 값으로 파일을 채웁니다. 또는 텍스트 편집기에서 이러한 파일을 만들고 값을 수동으로 대체할 수 있습니다.
[[["이해하기 쉬움","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)."]]