2013-12-21 16 views
7

我下載了一個mongodb轉儲文件。現在我正試圖將文件從轉儲文件移動到我的mongodb位置。我正在使用mongorestore --dbpath [mongodb path] [轉儲路徑] cmd來執行此操作。但是我在命令提示符中看到了太多位置選項錯誤。任何人都可以幫助我解決這個問題。做「mongorestore」時,「太多位置選項」是什麼意思?

這是命令行錯誤:

C:\Documents and Settings\>mongorestore -dbpath C:\Program Files\Mon 
goDb\data\db C:\Documents and Settings\My Documents\localadventure 
s\localadventures 
ERROR: too many positional options 

Import BSON files into MongoDB. 

我今天又試了一次,在我的命令提示符看到以下消息:

C:\>mongorestore --dbpath "C:\Program Files\MongoDb\data\db" "C:\Documents and S 
ettings\seemanapallik\My Documents\localadventures\localadventures" 
Mon Dec 23 09:05:01.515 [tools] C:\Documents and Settings\seemanapallik\My Docum 
ents\localadventures\localadventures\adventure.bson 
Mon Dec 23 09:05:01.515 [tools]   going into namespace [localadventures.ad 
venture] 
Mon Dec 23 09:05:01.531 [tools] warning: Restoring to localadventures.adventure 
without dropping. Restored data will be inserted without raising errors; check y 
our server log 
1 objects found 
Mon Dec 23 09:05:01.546 [tools]   Creating index: { key: { _id: 1 }, ns: " 
localadventures.adventure", name: "_id_" } 
Mon Dec 23 09:05:01.546 [tools] C:\Documents and Settings\seemanapallik\My Docum 
ents\localadventures\localadventures\patch_version.bson 
Mon Dec 23 09:05:01.546 [tools]   going into namespace [localadventures.pa 
tch_version] 
Mon Dec 23 09:05:01.546 [tools] warning: Restoring to localadventures.patch_vers 
ion without dropping. Restored data will be inserted without raising errors; che 
ck your server log 
2 objects found 
Mon Dec 23 09:05:01.562 [tools]   Creating index: { key: { _id: 1 }, ns: " 
localadventures.patch_version", name: "_id_" } 
Mon Dec 23 09:05:01.562 [tools] C:\Documents and Settings\seemanapallik\My Docum 
ents\localadventures\localadventures\PaxHeader\adventure.bson 
Mon Dec 23 09:05:01.562 [tools]   going into namespace [PaxHeader.adventur 
e] 
assertion: 16619 code FailedToParse: FailedToParse: Expecting '{': offset:0 
Mon Dec 23 09:05:01.578 dbexit: 
Mon Dec 23 09:05:01.578 [tools] shutdown: going to close listening sockets... 
Mon Dec 23 09:05:01.578 [tools] shutdown: going to flush diaglog... 
Mon Dec 23 09:05:01.578 [tools] shutdown: going to close sockets... 
Mon Dec 23 09:05:01.578 [tools] shutdown: waiting for fs preallocator... 
Mon Dec 23 09:05:01.578 [tools] shutdown: closing all files... 
Mon Dec 23 09:05:01.609 [tools] closeAllFiles() finished 
Mon Dec 23 09:05:01.609 [tools] shutdown: removing fs lock... 
Mon Dec 23 09:05:01.609 dbexit: really exiting now 
+2

我懷疑你的'轉儲路徑'包含空格嗎? – bsd

+1

如果包含完整的命令行,它會有所幫助。該錯誤意味着給出的命令行參數數量與您指定的選項不匹配。如@bsd所述,這可能是dbpath或轉儲路徑中的空格。請注意,如果您不恢復到正在運行的MongoDB實例,則只應指定'--dbpath'。 'dbpath'選項直接訪問數據文件。 – Stennie

+0

@Stennie:我實際上正在嘗試恢復到正在運行的MongoDB實例。那麼,在這種情況下,我應該使用什麼選項來代替dbpath? – Newbee

回答

13

C:\Documents and Settings>mongorestore -dbpath C:\Program Files\MongoDb\data\db C:\Documents and Settings\My Documents\localadventures\localadventures ERROR: too many positional options

如果你有文件名或目錄包含空格的路徑,這些需要用雙引號引起來。否則命令行程序(如mongorestore)可能會合理地預期空格字符是新參數的開始,而不是前一個值的延續。

提示:如果您使用TAB自動完成Windows cmd.exe shell中的文件名,應自動添加正確的引號。

假設C:\Documents and Settings\My Documents\localadventures\包含您mongodump文件,預期mongorestore用法是:

> mongorestore "C:\Documents and Settings\My Documents\localadventures\localadventures" 

或者,你也可以切換到轉儲目錄首先要節省一點打字/報價。相對路徑工作得很好:

> cd "C:\Documents and Settings\My Documents\localadventures\" 
> mongorestore localadventures 

您應該只包括--dbpath參數,如果你是直接恢復到數據文件和到正在運行的MongoDB服務器實例。

MongoDB手冊中還有一些examples of mongorestore usage

3

預警給別人!我遇到了一個類似的問題,這是由於在TextEdit中保存命令,然後只是複製和粘貼而引起的。 TE必須一直影響空格和破折號。

+1

上次我將文本複製/粘貼到TextEdit中! – djheru

0

我的問題是沒有帶雙連字符的設置標誌。而不是像這樣設置數據庫--d dbname,我做了這個-d dbname。哎呀!