1

I can't import data into my existing database located on mongoDBAtlas. I installed and connected robomongo with mongoDBAtlas for working with atlas.

I created new database jasper and collection User in robomongo then I created user.json file in my project where are stored my data.

I followed tutorial on https://docs.atlas.mongodb.com/import/mongoimport/ - how to use mongoimport with mongodb.

Here is my command, Im typing in terminal:

mongoimport --uri mongodb://Morty:<PASSWORD>@jasper-shard-00-00-mrihb.mongodb.net:27017/jasper?ssl=true&replicaSet=jasper-shard-0&authSource=admin --collection User --drop --file ./src/data/user.json --jsonArray

that give me an error:

[1] 40930
[2] 40931
-bash: --collection: command not found
[2]+  Done                    replicaSet=jasper-shard-0
KSC1-LMC-K00587:Interview-test-part-one marze$ 2017-10-15T10:38:35.209+0200 no collection specified
2017-10-15T10:38:35.209+0200    using filename '' as collection
2017-10-15T10:38:35.209+0200    error validating settings: invalid collection name: collection name cannot be an empty string
2017-10-15T10:38:35.209+0200    try 'mongoimport --help' for more information       

If I run mongoimport for localhost it works perfectly.

Where should be the problem ?

Morten
  • 133
  • 4
  • 15
  • 1
    Put quotes around the uri connection string. You have an `&` in there which your shell ( bash,zsh, whatever ) thinks you mean something different by. – Neil Lunn Oct 15 '17 at 08:58
  • @NeilLunn really thanks for advice. That was the problem :) – Morten Oct 15 '17 at 09:00
  • FYI. Any document that is telling you to specify `authSource=admin` is really out of date. The general drivers ( and therefore the tools ) just do this by default, so it's not really needed. It's also a compatibilty issue for upcoming MongoDB 3.6 if there are users defined anywhere else other than `admin`. – Neil Lunn Oct 15 '17 at 09:01
  • @Morten could you post an answer to the question yourself instead of editing it in to help future readers? – LW001 Oct 15 '17 at 09:15
  • May be useful this answer https://stackoverflow.com/questions/53078520/mongodb-how-to-import-dump-data-from-gz-file/53079408#53079408 – Hardik Shah Aug 10 '19 at 07:04

1 Answers1

2

Solution: -use quotes for uri param.

mongoimport --uri "mongodb://Morty:<PASSWORD>@jasper-shard-00-00-mrihb.mongodb.net:27017/jasper?ssl=true&replicaSet=jasper-shard-0&authSource=admin" --collection User --drop --file ./src/data/user.json --jsonArray
Morten
  • 133
  • 4
  • 15