簡體   English   中英

mongorestore語法錯誤

[英]mongorestore syntax error

我在以下路徑中有很多bson文件:

c:/mongodb/bin/dump/Sid

如果我運行命令:

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

我收到以下錯誤:

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

我的命令有什么問題?

從您的輸入看來,您似乎正在嘗試從JS Shell內部運行mongorestore。

Mongorestore是一個獨立的應用程序,直接從終端運行。

以下內容不起作用:

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
>

如果直接從終端運行mongorestore,則應該成功:

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>

關於Mongodump / mongorestore的文檔可以在“導入導出工具”文檔中找到: http : //www.mongodb.org/display/DOCS/Import+Export+Tools

mongorestore不是命令 ,而是MongoDB bin目錄中的可執行文件。 以下是來自http://docs.mongodb.org/manual/reference/program/mongorestore/的報價

mongorestore程序將數據從mongodump創建的二進制數據庫轉儲寫入MongoDB實例。 mongorestore可以創建新數據庫或將數據添加到現有數據庫。

如果您已經有一個mongod實例在運行,並且您已將dbpath指定為

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

您可以直接運行mongorestore命令。

mongorestore ..\data\dump

您不能像這樣使用mongorestore命令...您必須通過cmd而不是在Mongo Shell上運行它...看看下面的命令...

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

這里path\\to\\mongorestore.exe是路徑mongorestore.exe MongoDB的內部bin文件夾中。 dbname是數據庫的名稱。 collection_name是名collection.bson path/to/same/collection.bson是該path/to/same/collection.bson的路徑。

現在,您可以從mongo shell驗證是否已創建數據庫(如果不存在,則將使用collection創建具有相同名稱的數據庫)。

如果要還原外部數據庫,請將該數據庫復制到

<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>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM