Reputation: 207
Trying to import a JSON file
Mongodb Version -- V3.6.3
Shell Version 3.6
Using this command to connect to cluster and import
mongoimport --host cluster0-shard-00-00-xxm0e.mongodb.net:24537 --db ny --type json --file C:/data/docs/ny.json --jsonArray --authenticationDatabase admin --ssl --username xyz --password mongodb
error message
2018-03-03T22:53:45.477-0800 no collection specified
2018-03-03T22:53:45.478-0800 using filename 'ny' as collection
2018-03-03T22:53:46.062-0800 Failed: error connecting to db server: server` returned error on SASL authentication step: bad auth Authentication failed.
2018-03-03T22:53:46.062-0800 imported 0 documents
Have tried a few options like removing -ssl adding ----sslAllowInvalidCertificates Adding " C:/data/docs/ny.json" to file name and none of these works.. Any help appreciated
Upvotes: 5
Views: 15154
Reputation: 216
We can easily import/export with the command line:
mongoimport --uri mongodb+srv://<USERNAME>:<PASSWORD>@your-cluster.mongodb.net/<DATABASE_NAME> --collection <COLLECTION> --type <FILETYPE> --file <FILENAME>
mongoexport --uri mongodb+srv://<USERNAME>:<PASSWORD>@your-cluster.mongodb.net/<DATABASE_NAME> --collection <COLLECTION> --type <FILETYPE> --out <FILENAME>
You can also find these on Your Cluster > Cmd Line Tools
Official Docs: MongoDB Import Export
Or using MongoDB Compass Import Export
Upvotes: 4
Reputation: 3953
You have to specify the collection -c or --collection
flag. see official docs.
mongoimport
--host <HOST>
--ssl --username <USERNAME>
--password <PASSWORD>
--authenticationDatabase admin
--db <DATABASE>
--collection <COLLECTION>
--type <FILETYPE>
--file <FILENAME>
Upvotes: 8
Reputation: 71
You missed specifying the collection name :
mongoimport --host cluster0-shard-00-00-xxm0e.mongodb.net:24537 --db ny --collection <entercollectionName> --type json --file C:/data/docs/ny.json --jsonArray --authenticationDatabase admin --ssl --username xyz --password mongodb
try the command now
Upvotes: 2