我在下面的路径中有很多bson文件:
c:/mongodb/bin/dump/Sid如果我运行以下命令:
> mongorestore --db Sid --drop dump/Sid我得到以下错误:
Mon Mar 26 14:36:36 SyntaxError: missing ; before statement (shell):1我的命令有什么问题?
发布于 2012-03-26 23:36:37
从您的输入来看,您似乎正在尝试从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的文档可以在"Import Export Tools“文档中找到:http://www.mongodb.org/display/DOCS/Import+Export+Tools
发布于 2014-08-23 02:22:24
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发布于 2015-01-02 18:25:54
你不能像这样使用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是通向该集合的路径。
现在,您可以从mongo shell验证是否创建了数据库(如果不存在,将使用集合创建具有相同名称的数据库)。
https://stackoverflow.com/questions/9872286
复制相似问题