Syntax error while mongorestore

I keep getting an error from a semicolon when I want to use the mongorestore command to upload the database.

You are running the command at Mongo prompt
Run it at os prompt


Hi Ramachandra, could you elaborate what you meant by running it at OS prompt?


When you first open the command prompt / terminal window, before you run the mongo ... command, you’re in your operating system’s shell, that’s what Ramachandra means by the OS prompt. Once you’ve run the mongo ... command you’re in the Mongo shell rather than your operating system’s shell.

mongorestore is a command which needs to be run in the operating system’s shell rather than the Mongo shell.

I hope this clarifies things?

Yes, that does thank you.
But after initiating a connection to atlas, I’ve tried running the mongostore command in the OS shell and it does not recognize mongostore.

mongo**re**store, not mongostore

Oh yes sorry for that typo, I ran mongorestore. It does not recognize that command.

Also not sure if its relevant - I have MongoDB Enterprise server installed and not the Community Server.

Hmm, are you getting an error similar to

'mongorestore' is not recognized as an internal or external command,
operable program or batch file.


Try this command:

echo %path%

This will list all the paths in your path environment variable, which should include something similar to

C:\Program Files\MongoDB\Server\4.0\bin

That folder should contain mongorestore.exe, and adding the folder to your path environment variable lets you run it without supplying the fully qualified path to the .exe file, the same way it allows you to run mongo.exe without supplying the fully qualified path.

Incidentally, are you able to run the mongo command to start the Mongo shell?

I have the enterprise edition installed too, all the courses I’ve done so far recommend installing this rather than the community edition, although I don’t think it should make a difference in this case.

Disclaimer - all of the above assumes that you’re using Windows (because that’s what I’m using), if you’re using another operating system then the commands will be a bit different but I believe the general principle still applies.

Sorry for the delay - Its working now.

I was strangely able to run the mongo command to start the Mongo shell even though when I echo %path I don’t see MongoDB in my path.

However, when I try to edit the path in my environment variables in my Windows Advanced System Settings, I see that C:\Program Files\MongoDB\Server\4.0\bin is present right at the top. I tried moving the mongo path variable to the bottom and then when I echo %path%, I did see MongoDB in my path. mongorestore was working after that.

I don’t know if thats happened before to others or I missed something in the setup! But if I didn’t miss any instructions it was definitely strange.

Thanks for the help!

1 Like

No worries, glad you got it working :slight_smile:

1 Like