ma_jafari
ma_jafari

Reputation: 1059

mongorestore uncaught exception: syntax error

I've dumped some databases using mongodump which means that I currently have a folder(which name, is the date I dumped the databases) and one folder for each database that I had and inside each database folder I have 2 files per collection, one .bson and one .metadata.json.

Now I want to use mongorestore to rebuild databases and their collections using the following command:

 mongorestore --db user --verbose /home/nvsh120/projects/database/11-26-20/user

but it doesn't work and exits with the following error:

uncaught exception: SyntaxError: unexpected token: identifier :
@(shell):1:15

Upvotes: 1

Views: 2614

Answers (2)

PWJ
PWJ

Reputation: 81

In case someone needs this, it is for running a mongorestore command for a docker pulled DB.

You cannot run the mongorestore in the docker mongo shell.

First run the command to get the bash of the specific docker container:

sudo docker exec -it <name-of-container> bash

Next, run the restore command in this bash.

root@52f66390ae10:/# mongorestore -d <db-name> <path-to-dump-in-docker-container>

Keep in mind, I have run my Docker MongoDB with a docker-compose.yml file in which I have mounted the database dump as a volume.

Here is a snippet from the docker-compose file:

volumes:
            - <path-to-dump-in-local>:<path-to-db-in-container> (Usually /data/db)

Volumes can also be mounted as a part of the docker run command.

Upvotes: 0

ma_jafari
ma_jafari

Reputation: 1059

So the problem was that I was trying to run mongorestore from mongo shell whereas I should've run it from windows\linux command prompt\terminal.

Upvotes: 9

Related Questions