Mongorestore syntax error

I have many bson files in the following path:

c:/mongodb/bin/dump/Sid 

If I run the command:

 > mongorestore --db Sid --drop dump/Sid 

I get the following error:

 Mon Mar 26 14:36:36 SyntaxError: missing ; before statement (shell):1 

What is the problem with my team?

+4
source share
4 answers

From your input, it seems like you're trying to run mongorestore from inside the JS shell.

Mongorestore is a standalone application and runs directly from the terminal.

The following actions will not be performed:

 c:\mongodb-win32-x86_64-2012-03-20\bin>mongo.exe MongoDB shell version: 2.1.1-pre- connecting to: test > mongorestore --db test --drop \dump\test Mon Mar 26 11:29:13 SyntaxError: missing ; before statement (shell):1 > 

If you run mongorestore directly from the terminal, you must be successful:

 c:\mongodb-win32-x86_64-2012-03-20\bin>mongorestore --db test --drop \dump\test connected to: 127.0.0.1 ... (truncated for brevity) ... c:\mongodb-win32-x86_64-2012-03-20\bin> 

The Mongodump / mongorestore documentation can be found in the Export Export Tools documentation: http://www.mongodb.org/display/DOCS/Import+Export+Tools

+21
source

mongorestore is not a command , it is an executable in the MongoDB bin directory. Below is a quote from http://docs.mongodb.org/manual/reference/program/mongorestore/

The mongorestore program writes data from a binary database dump created by mongodump for the MongoDB instance. mongorestore can create a new database or add data to an existing database.

If you already have a mongod instance where you already specified dbpath as

 mongod --dbpath "..\mongodb\data" 

you can directly run the mongorestore command.

 mongorestore ..\data\dump 
+3
source

You cannot use the mongorestore command like this ... you should run this via cmd and not on Mongo Shell ... See below command ...

 >path\to\mongorestore.exe -d dbname -c collection_name path\to\same\collection.bson 

Here path\to\mongorestore.exe is the path to mongorestore.exe inside the mongodb bin folder. dbname is the name of the database. collection_name is the name of collection.bson . path/to/same/collection.bson - the path to this collection.

Now from the mongo shell you can verify that the database is created or not (if it does not exist, a database with the same name will be created using the collection).

+1
source

If you want to restore an external database, then copy this database to

 <pre>C:\database drive(Create a folder database and copy your database) ,then follow the steps 1)c:\> cd database 2)c:\database>dir 3)c:\database>"\Program Files\MongoDB\Server\3.0\bin\mongorestore.exe" now open robomongo and check it will contain the restored dbs.. or check on command prompt show dbs</pre> 
0
source

Source: https://habr.com/ru/post/1403457/


All Articles