'no collection specified' error when trying to import from local into remotehost

mongoimport --host=myRemoteHost.cloud --port=30107 --username=my_cloud_user
 --collection=profiles --db=controlpanel --file=/Users/myLocal/Documents/language profiles/languageprofiles.json

prompts me the following message:

2022-09-28T19:25:51.390-0300 no collection specified
2022-09-28T19:25:51.391-0300 using filename ’ ’ as collection
2022-09-28T19:25:51.391-0300 error validating settings: invalid collection name: collection name cannot be an empty string

zsh: command not found: --collection=profiles

Not sure what I am missing here. As per what I read at the documentation, --collection is valid.

Hello @Wesley_Melis, and welcome to the MongoDB community forums! :wave:

I get the same result as you if I try to run the command as you have entered it here in the forums. As you can see from the last line zsh: command not found --collection=profiles, this means you’re trying to run the command split over two lines withe continuation character. You either need to put that on a single line, or write the command as follows:

mongoimport --host=myRemoteHost.cloud --port=30107 --username=my_cloud_user \
--collection=profiles --db=controlpanel --file=/Users/myLocal/Documents/language\ profiles/languageprofiles.json

Notice the \ at the end of the first line which means that the command continues on the next line.

Also note that your file path has a space in it which means you’'ll get another error, so you will want escape the space with another \ character as I have done in the command above.

Doing both of those things should allow you to import your file.

Hello @Doug_Duncan

Your suggestions had some effect. I added the “” to continue the command at the nextline and fixed my file path too.

Now I run into a different issue.

2022-09-29T09:42:22.173-0300	error connecting to host: could not connect to server: server selection error: server selection timeout, current topology: { Type: Single, Servers: [{ Addr: myRemoteHost.cloud:30107, Type: Unknown, Last error: connection() error occurred during connection handshake: connection(myRemoteHost.cloud:30107[-64]) socket was unexpectedly closed: EOF }, ] }

Don’t know if this eof either suggests something wrong with the connection string itself or my .json file. Or if I should use --uri instead of --host

I changed my approach a little bit by issuing our cloud mongodb:// string

mongoimport mongodb://myUser@myRemoteHost.cloud:30107,myRemoteHost.cloud:30107,myRemoteHost.cloud:30107/clouddb?authSource=admin&replicaSet=replset --collection=profiles --db=myDatabase --mode=upsert --file=/Users/wesley/Documents/UAT28SEP/profilesprod.json

I think I’m missing the ""again. Tried to inser it at different positions, but still I get a

[1]  + exit 1     mongoimport 
zsh: command not found: --collection=profiles

The ? character is a special character in Linux shells, so that needs to be escaped. Using the URI format, it’s best just to put that string in quotes so you don’t have to worry about escaping the characters.

The updated command would look like this:

mongoimport "mongodb://myUser@myRemoteHost.cloud:30107,myRemoteHost.cloud:30107,myRemoteHost.cloud:30107/clouddb?authSource=admin&replicaSet=replset" --collection=profiles --db=myDatabase --mode=upsert --file=/Users/wesley/Documents/UAT28SEP/profilesprod.json

Now having said that you’ll still get an error:

2022-09-29T09:12:03.566-0600    error parsing command line options: Invalid Options: Cannot specify different database in connection URI and command-line option ("clouddb" was specified in the URI and "myDatabase" was specified in the --db option)
2022-09-29T09:12:03.567-0600    try 'mongoimport --help' for more information

To answer your original question, it looks like there was a timeout connecting to the server. Can you connect using:

mongo --host=myRemoteHost.cloud --port=30107 --username=my_cloud_user -p
1 Like