Search code examples
azureazure-cosmosdbdatabase-migrationazure-cosmosdb-mongoapi

Fatal error while migrating Cosmos DB Emulator (MongoDB API) to Azure


I'm having a lot of issues migrating a localhost Cosmos DB database hosted in the Cosmos DB Emulator to an online Cosmos DB instance on Azure. I have used Microsoft's data migration tool to upload the current database, converted to JSON files, to a storage account, and using a Data Migration Service to pull the data from the storage account, to the Cosmos DB database, according to the steps shown here.

At the start of the migration, i get the following fatal error:

Cannot deserialize a 'BsonDocument' from BsonType 'Array'

I don't know how to proceed. Does anyone have experience with such conversions and know how to get past this error?


Solution

  • For when others encounter this same problem in the future: I applied the following to make this work:

    • Download Mongodump Full MongoDB Server download here
    • Dump the Cosmos DB emulated database using mongodump
    • Copy the resulting .bson and metadata files to an Azure Storage account (Blob storage)
    • Get a SAS url for this account using Azure Storage Explorer
    • Create a new Azure Database migration service (MongoDB => Cosmos DB (MongoDB API))
    • Set Azure Storage as source, and enter the SAS url
    • Set your Cosmos DB database as the target

    Using mongodump, the data gets generated into a file structure which Cosmos DB understands.