Issue doing mongo import to Azure Cosmos Emulator - mongodb

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

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"

Related

in mongodb is it possible to backup and restore a specific collection in database?

In mongodb is it possible to backup and restore a single collection in database?. Recently came across a database which which started as VM1 (primary) and VM2 (secondary) which at some point it time has failed over to VM2 (new primary) and VM1(New Secondary). When I took over the database looked at the collection in a database notices one of the collections in the database VM1 is not there in VM2.
Is there a way I can backup that specific collection in the database delete the collection and then import it to VM2 (New Primary) in the same database?
To export a specific collection use the below syntax
mongodump --port 27020
--db test
--collection restaurants
--out /mydata/restoredata/
To import to another VM - do the below
mongorestore --port 27017 --db test2 --collection rest2 /mydata/restoredata/test/restaurants.bson --drop
More details here -
https://docs.cloudmanager.mongodb.com/tutorial/restore-single-database/

ETL to import data into MongoDB

I would like to know about an ETL tool to upload data into a MongoDB, I've tried with Pentaho and Talend, but I would prefer something a bit lighter, because my process is so simple.
Thanks!
Assume you have a JSON file 'test.json' (and also assume it is valid JSON) you can use command line program mongoimport.
Example:
mongoimport --host localhost:27017 --db test --collection test --username johndoe --password my secret --authenticationDatabase admin --file test.json

Unable to get records from atlas after migrate local mongo db into atlas

i migrate local db into atlas using following process
export db collection one by one using mongoexport --db bla
--collection usersettings --jsonArray --out ~/Desktop/users.json command
import these collection on atlas using mongoimport --host
cluster0-shard-00-00-c7jiq.mongodb.net:27017 --db Eltar --type json
--file ~/Desktop/userotp.json --authenticationDatabase admin --ssl --username name --password pass command
Now, when i connect to local mongo shell and run the query db.users.find() it shows all the record but when i run the same query db.users.find() after connecting atlas shell it shows only one record.
Records are showing on atlas but unable to get them using query
dont know what i am doing wrong here, any help will be appreciated thanks.
Done by migrating mongo db to mlab instead of mongo db atlas, still don't know the issue. But everything works fine on mlab

how to copy a collection from one from another in robomongo

I have a collection named dashboard in one db and i want to copy that collection to another db using robomongo. How can i do this? I tried creating a new collection in 2nd db and tried copying but it failed. so somebody please help me
Another db - another connection. But Robomongo works only with one connection in one period of time. That is why it is impossible.
I suggest you to use mongoimport/mongoexoprt tools for your task. They comes with mongo, are located in same folder as mongod.exe and allows to move collections via databases, by exporting to and importing from a json file.
Code sample:
mongoexport --db testFrom --port portFrom --username userFrom --password passwordFrom --collection yourCollection --out test.json
mongoimport --db testTo --port portTo --username userTo --password passwordTo --collection yourCollection --file test.json

How can I create a database in mongodb and import the data from a csv to its collection

I am not able to figure out,how to create a database in mongodb.
When I login in to the mongo console it shows me test database as default. What are the steps to create a new database?
In MongoDB, to create a database from within the Mongo shell you use
use mydatabasename
where mydatabasename is the name you want to give to the database. If you want to list the databases
show dbs
The shell quick reference documentation is pretty good.
For importing data from a CSV file, you can use mongoimport
Whenever we login into mongo without passing any parameter, say db or hostname, it will automatically connect you with test db.
In order to create DB and dump data from CSV you can use the following command :-
mongoimport --db nxtshow --collection movies --type csv --file ./mongo/movies.csv --fields id,imdb_url,release_date,title,video_release_date