Mongoimport doing nothing

Hey y’all, trying to import a csv file into my MongoAtlas collection.

This is the command I run in terminal:

mongoimport --uri mongodb+srv://Jfreundlich01:<PASSWORD>@seir-cluster.sclij.mongodb.net/Optimizer --collection Players --type csv --file "Seed.csv"

When I click return it goes to a new line in my terminal but nothing happens.

After I run that line, if I type mongoimport --help or --version or any of those options, I get:

no such file or directory: <part of my password>@seir-cluster.sclij.mongodb.net/Optimizer

Any help/guidance would be greatly appreciated!

Thanks

Are you able to connect to your cluster with your uri connect string?
Have you removed “<>” in password?
No need of enclosing Seed.csv in quotes unless you are giving full path

if you are on windows, enclose your URI in quotes. Windows does not like : in your commands.

Yea I can connect to the cluster using the uri connect string. And yea I have my password in there, just didn’t want to put that up… I am on mac but it still wont work without quotes

Well to clarify I can connect with

mongodb+srv://Jfreundlich01:<password>@seir-cluster.sclij.mongodb.net/?retryWrites=true&w=majority

But if i try

mongodb+srv://Jfreundlich01:<password>@seir-cluster.sclij.mongodb.net/optimize

The same issue occurs, goes to new line, but nothing happens.

Try to split your command into multiple lines using back slash

mind showing what that would look like? Thanks

Just tried it after every mongoimport option, and it still did the same thing.

Does your password have an * or any other special characters in it by chance? If so you will want to URL encode those characters.

2 Likes

Hey Doug thanks for chirping in! It does have special characters, but I have been able to connect to the db several times using the same password in projects. mongoimport is the first time it has given me an issue. I’ll check out how to URL encode those characters and give it ago.

OMG that worked! Wow thanks so much. Would have never thought to do that. Any guesses why you have to do that for mongoimport and not other times you connect to database?

1 Like

It depends on the tool and if it works some magic behind the scenes for you in this regard. I think that all tools would be able to use the URL encoded values without issue.

some characters are used by the shell unless quoted. few of them are very important as they cause a start of a multi-line command mode, single quote ' , double quote ", backtick ` and backslash \. your new line description fits in this type of control character.

however, in most situations, simply surrounding the whole URI with double quotes (as it should not have double quote in it anyways) should solve the problem without extra encoding.

2 Likes

After I had a chance to think about this (was busy during my initial response), the problem is not with mongoimport but with the special character.

Since you were getting en error message with just the end portion of your password and cluster name per your original message:

I’m assuming the special character was an & and you had everything after that character in the error message.

The & character is a special character in Linux which will run the command in the background. If you typed ctrl + c to end that command you should have seen something similar to the following:

[1]+ Exit 1               mongoimport <any characters up to the &>

You could also just escape the & (or any other shell specific special character such as *) by preceding that character with a \ (e.g. \&). This will stop the shell from treating that character as special and treating it as the literal value that it is.

This would happen on any tool that you typed that password into on the command line (at least in a Linux/Mac based system). I’m assuming most times, you’re typing the password in at a prompt, in which case you don’t need to escape the special character as you’re no longer working with prompt directly.

Hopefully this clears up what was going on and that I didn’t muddy the waters trying to explain what was happening.

1 Like

This works as well, but I don’t like using quotes which is why I never think to mention it. :smiley:

Muscle memory has gotten me used to escaping special shell characters and I don’t think about quoted strings.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.