0
votes

I am trying to restore data to the Azure Cosmos DB Emulator from MongoDB in order to test my Application. I originally used the Data Import Tool but realised after reading the Documentation this is for use with the SQL API for Cosmos DB while I want to be using the MongoDB API.

I successfully exported my Data from Mongo to json file with the command line:

D:\MongoDb\bin>mongoexport.exe --db Vehicles --collection Cars --out C:\Temp\Cars.json
2018-09-18T10:02:21.210-0400    connected to: localhost
2018-09-18T10:02:21.212-0400    exported 100 records

I am then trying to import this into Azure Cosmos DB Emulator with below command

D:\MongoDb\bin> mongoimport.exe --host localhost:10255 -u admin -p C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw== --ssl --sslAllowInvalidCertificates --db Vehicles --collection Cars --type json --file "C:\Temp\Cars.json"

However I am getting the following Error:

2018-09-18T11:00:38.829-0400    Failed: error connecting to db server: Database Account admin does not exist
ActivityId: ada5953a-0000-0000-0000-000000000000, Microsoft.Azure.Documents.Common/1.22.0.0
2018-09-18T11:00:38.830-0400    imported 0 documents

I had created a DB in the Azure Cosmos DB Emulator called Vehicles with a Cars collection so not sure what I am doing wrong - or can the Azure Cosmos Emulator not be used for what I am attempting?

I tried changing the admin to Vehicles in the command line script but get the same error.

From the Azure Cosmos DB Emulator this is my Mongo Connection string which is where I was pulling the details from for the import

mongodb://localhost:C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw==@localhost:10255/admin?ssl=true

Ideally I want to get the Emulator running as a way to test things locally

1
Have you tried using localhost as the user name? By that I mean. in the mongiimport.exe string use -u localhost instead of -u admin.Nick Chapsas
yeah - I just tried @localhost:10255/adminCtrl_Alt_Defeat
No, no port. Just localhost. Like this: D:\MongoDb\bin> mongoimport.exe --host localhost:10255 -u localhost -p C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw== --ssl --sslAllowInvalidCertificates --db Vehicles --collection Cars --type json --file "C:\Temp\Cars.json"Nick Chapsas
@NickChapsas = just localhost worked - cheers....again :) :)Ctrl_Alt_Defeat
No problem :) I added the answer.Nick Chapsas

1 Answers

1
votes

The DatabaseAccount name in the CosmosDB emulator is localhost not admin so your mongoimport.exe string should look like this:

D:\MongoDb\bin> mongoimport.exe --host localhost:10255 -u localhost -p C2y6yDjf5/R+ob0N8A7Cgv30VRDJIWEHLM+4QDU5DE2nQ9nDuVTqobD4b8mGGyPMbIZnqyMsEcaGQy67XIw/Jw== --ssl --sslAllowInvalidCertificates --db Vehicles --collection Cars --type json --file "C:\Temp\Cars.json"