La procedura di migrazione utilizza gcloud CLI per configurare e
attivare i passaggi della migrazione. Se necessario, installa gcloud CLI seguendo le istruzioni riportate nella pagina Installa gcloud CLI.
Configurazione specifica per l'origine
MongoDB su Compute Engine
Un database MongoDB in esecuzione su VM di Compute Engine in un cluster autogestito
non è normalmente esposto a internet pubblico. La procedura di migrazione utilizzerà Private Service Connect in Datastream per connettere la pipeline Datastream al database di origine.
Prendi nota del parametro Configuration ID della configurazione creata. Lo utilizzerai nelle fasi successive per configurare le variabili di ambiente richieste.
Azure Cosmos DB
Assicurati che
Azure CLI
sia installata sul tuo computer.
Amazon DocumentDB
I cluster Amazon DocumentDB non sono accessibili direttamente dall'esterno della rete Amazon VPC. Per connetterti a un cluster DocumentDB, devi eseguire il provisioning
di un'istanza EC2 all'interno della rete Amazon VPC e utilizzarla come
host bastion per un tunnel SSH.
Per stabilire una connessione al cluster DocumentDB, devi ottenere
la chiave SSH privata per l'istanza EC2, nonché il bundle di certificati
appropriato per la regione in cui è implementato il cluster. Visita la pagina delle risorse
Bundle di certificati per regione AWS
per scaricare il bundle appropriato in formato PEM.
Tieni presente che il bundle di certificati contiene più certificati. Devi estrarre un singolo certificato per configurare una connessione Datastream. Ti consigliamo di convalidare manualmente la connettività DocumentDB per assicurarti di disporre di una chiave SSH valida e di un certificato DocumentDB valido dal bundle regionale. La guida per gli sviluppatori di DocumentDB fornisce esempi di riga di comando per stabilire una connessione diretta dall'esterno
del VPC.
Configura un database di destinazione Firestore con compatibilità MongoDB
Assicurati che il tuo progetto abbia un database Firestore con compatibilità MongoDB in cui eseguire la migrazione dei dati dal database MongoDB di origine. Per saperne di più sulla creazione di un database, vedi Creare e gestire database.
Ai fini di questa migrazione, ti consigliamo di
creare un nome utente e una password
per il database Firestore con compatibilità MongoDB da
utilizzare con il protocollo di autenticazione SCRAM-SHA-256. Questo nome utente può essere
eliminato in sicurezza al termine della migrazione oppure puoi scegliere di continuare
a utilizzare queste credenziali per connettere i client MongoDB al nuovo
database Firestore con compatibilità MongoDB.
Utilizzerai il nome di questo database Firestore con compatibilità MongoDB e le credenziali utente nei passaggi successivi.
Modificare le dimensioni della finestra oplog del database di origine
Ti consigliamo di regolare la finestra oplog del database Mongo di origine in modo che contenga tre giorni
di traffico di scrittura totale in questo database. Se il tasso di traffico di scrittura
supera la velocità con cui Datastream può utilizzare le modifiche del
database, questo aggiustamento impedirà la perdita di dati.
Il valore potrebbe dover essere ulteriormente modificato, a seconda del pattern del
traffico e del volume di picco. Ad esempio, se il traffico di una settimana viene scritto in un breve periodo di tempo, Datastream potrebbe non acquisire le modifiche dall'oplog abbastanza rapidamente prima che le modifiche escano dalla finestra oplog. In questo caso, potrebbe essere necessario ridimensionare la finestra oplog
a 7 giorni di traffico di scrittura totale.
Crea un bucket Cloud Storage
Crea un nuovo bucket Cloud Storage nel seguente modo:
Scegli una regione Cloud Storage in cui verrà eseguita la pipeline di migrazione. Ti consigliamo di utilizzare la regione in cui si trova il database Firestore di destinazione con compatibilità MongoDB.
Scegli il nome per questo bucket. Esempio: mongo-migration-bucket. Utilizzerai questo nome nei passaggi successivi.
Crea un nuovo bucket Cloud Storage con il nome scelto e nella regione scelta seguendo le istruzioni fornite nella pagina Crea un bucket della documentazione di Cloud Storage.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-04 UTC."],[],[],null,["# Configure resources for migration\n=================================\n\nThis page describes the preparation part of the\n[migration process](/firestore/mongodb-compatibility/docs/migrate-data)\nwhere you configure resources for the migration.\n\nAt this stage, you do the following:\n\n1. Install command-line tools required for running commands at later stages of the migration process.\n2. Configure Firestore with MongoDB compatibility database.\n3. (Optional) Adjust the operation log (oplog) settings on your MongoDB compatible source.\n4. Create a Cloud Storage bucket for intermediate data storage.\n\nConfigure IAM permissions\n-------------------------\n\nYour account requires appropriate IAM roles in all\nservices used in the migration process:\n\n- [Datastream roles](/iam/docs/roles-permissions/datastream)\n- [Dataflow roles](/dataflow/docs/concepts/access-control)\n- [Cloud Storage roles](/storage/docs/access-control/iam-roles)\n- [Datastore roles](/datastore/docs/access/iam)\n\nInstall command-line tools\n--------------------------\n\nThe migration procedure uses the gcloud CLI to configure and\nactuate the migration steps. If required, install the gcloud CLI by\nfollowing instructions on the [Install the gcloud CLI](/sdk/docs/install) page.\n\nSource-specific configuration\n-----------------------------\n\n### MongoDB on Compute Engine\n\nA MongoDB database that runs on Compute Engine VMs in a self-managed\ncluster isn't normally exposed to the public internet. The migration\nprocedure will use\n[Private Service Connect in Datastream](/datastream/docs/psc-interfaces)\nto connect the Datastream pipeline to your source database.\n\nDo the following:\n\n1. Configure Datastream Private Connectivity by following\n instructions outlined in\n [Create a private connectivity configuration](/datastream/docs/create-a-private-connectivity-configuration#create-the-configuration).\n\n2. Note the `Configuration ID` parameter of the created configuration. You\n will use it in later stages to set up required environment variables.\n\n### Azure Cosmos DB\n\nMake sure that\n[Azure CLI](https://learn.microsoft.com/en-us/cli/azure/install-azure-cli?view=azure-cli-latest)\nis installed on your computer.\n\n### Amazon DocumentDB\n\nAmazon DocumentDB clusters are not directly accessible from outside the Amazon\nVPC network. To connect to a DocumentDB cluster you will have to provision\nan EC2 instance within the Amazon VPC network, and use that instance as a\n[Bastion Host](https://en.wikipedia.org/wiki/Bastion_host) for an SSH tunnel.\n\nVisit the [Connecting to an Amazon DocumentDB cluster from outside an Amazon VPC](https://docs.aws.amazon.com/documentdb/latest/developerguide/connect-from-outside-a-vpc.html) developer guide for instructions on setting\nup an EC2 instance for external connectivity to DocumentDB.\n\nTo establish a connection to the DocumentDB cluster you will have to obtain\nthe private SSH key for the EC2 instance as well as the appropriate\nCertificate Bundle for the region in which your cluster is deployed. Visit the\n[Certificate bundles by AWS Region](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/UsingWithRDS.SSL.html#UsingWithRDS.SSL.CertificatesAllRegions)\nresource page to download the appropriate bundle in PEM format.\n\nNote that the Certificate Bundle contains multiple certificates. You have to\nextract a single certificate to set up the a Datastream connection. It is\nrecommended that you validate the DocumentDB connectivity manually to ensure\nthat you have both a valid SSH key and a valid DocumentDB certificate from\nthe regional bundle. The DocumentDB [developer guide](https://docs.aws.amazon.com/documentdb/latest/developerguide/connect-from-outside-a-vpc.html) provides commandline examples for establish a direct connection from outside\nthe VPC.\n\nConfigure a destination Firestore with MongoDB compatibility database\n---------------------------------------------------------------------\n\n1. Make sure that your project has a Firestore with MongoDB\n compatibility database where you will migrate data\n from your source Mongo database. For more information about creating a\n database, see\n [Create and manage databases](/firestore/mongodb-compatibility/docs/create-databases).\n\n2. For the purpose of this migration, we recommend to\n [create a username and password](/firestore/mongodb-compatibility/docs/connect#scram)\n for the Firestore with MongoDB compatibility database to\n use with the SCRAM-SHA-256 authentication protocol. This username can be\n safely deleted after the migration completes, or you may choose to keep\n using these credentials to connect your Mongo clients to your new\n Firestore with MongoDB compatibility database.\n\nYou will use the name of this Firestore with MongoDB\ncompatibility database and the user credentials in later steps.\n\nAdjust the oplog window size of the source database\n---------------------------------------------------\n\nWe recommend to adjust the oplog window of your source Mongo database to 3 days\nworth of total write traffic to this database. If the rate of write traffic\nexceeds the rate at which Datastream can consume changes from\nyour database, this adjustment will prevent data loss.\n\nThe value might need to be adjusted further, depending on the pattern of the\ntraffic and the volume of peak traffic. For example, if a week's worth of\ntraffic is written in a short period of time, then Datastream\nmight not capture the changes from the oplog fast enough before changes fall\nout of the oplog window. In this case you might need to resize the oplog window\nto 7 days worth of total write traffic.\n\nCreate a Cloud Storage bucket\n-----------------------------\n\nCreate a new Cloud Storage bucket in the following way:\n\n1. Choose a [Cloud Storage region](/storage/docs/locations) where the\n migration pipeline will run. We recommend to use the region where your\n destination Firestore with MongoDB compatibility database\n is located.\n\n2. Choose the name for this bucket. Example: `mongo-migration-bucket`. You will\n use this name in later steps.\n\n3. Create a new Cloud Storage bucket with the chosen name and in the\n chosen region by following instructions provided on the\n [Create a bucket](/storage/docs/creating-buckets#create-bucket) page in\n the Cloud Storage documentation.\n\nWhat's next\n-----------\n\nProceed to\n[Configure environment variables](/firestore/mongodb-compatibility/docs/migrate-configure-env-vars)."]]