Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing your data into MongoDB Atlas

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

like image 238
Puttur Kamath Avatar asked Mar 04 '18 07:03

Puttur Kamath


2 Answers

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>
like image 66
Anthony Awuley Avatar answered Sep 28 '22 01:09

Anthony Awuley


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

like image 35
Rishab Avatar answered Sep 28 '22 01:09

Rishab