mongodb Mongorestore 不知道如何处理文件“db/collection.bson”,跳过

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28954884/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 20:20:14  来源:igfitidea点击:

Mongorestore don't know what to do with file "db/collection.bson", skipping

mongodb

提问by Feng Yu

I want to migrate my mongodb from 2.0 to 3.0. So I followed the official doc to use mongodump to backup my dbs and use mongorestore to restore the dbs to mongodb 3.0.

我想将我的 mongodb 从 2.0 迁移到 3.0。所以我跟着official doc使用mongodump备份我的dbs并使用mongorestore将dbs恢复到mongodb 3.0。

But when I use mongorestore, it tells me "don't know what to do with file "db/collection.bson", skipping...".

但是当我使用 mongorestore 时,它​​告诉我“不知道如何处理文件“db/collection.bson”,跳过...”。

Nothing to do. How could I migrate my dbs?

没事做。我怎样才能迁移我的数据库?

Thanks.

谢谢。

EDIT: Here is my steps.

编辑:这是我的步骤。

Use mongodump in mongodb 2.0

在 mongodb 2.0 中使用 mongodump

mongodump
tree dump
    db
    ├── collection-1.bson
    ├── collection-2.bson
    ├── collection-3.bson
    ├── ...

Copy db directory to mongodb 3.0 server.

将 db 目录复制到 mongodb 3.0 服务器。

On the mongodb 3.0 server calls mongorestore db

在 mongodb 3.0 服务器上调用 mongorestore db

But I get this error:

但我收到此错误:

mongorestore db
2015-03-10T09:36:26.237+0800    building a list of dbs and collections   to restore from db dir
2015-03-10T09:36:26.237+0800    don't know what to do with file "db/collection-1.bson", skipping...
2015-03-10T09:36:26.237+0800    don't know what to do with file "db/collection-2.bson", skipping...
2015-03-10T09:36:26.237+0800    don't know what to do with file "db/collection-3.bson", skipping...
...
2015-03-10T09:36:26.237+0800    done

回答by Peter

It seems one must also specify -d in 3.0 like this:

似乎还必须像这样在 3.0 中指定 -d:

mongorestore -d db db

回答by Artem Dolobanko

This answer isn't directly related to your issue case, but the same error output you will receive trying to restore mongo data, dumped with --archiveoption, available since MongoDB 3.2 version. To resolve this you need to specify --gzipparameter in your mongorestorecommand. Example:

此答案与您的问题案例没有直接关系,但您将收到尝试恢复 mongo 数据的相同错误输出,使用--archive选项转储,自 MongoDB 3.2 版本起可用。要解决此问题,您需要--gzipmongorestore命令中指定参数。例子:

mongorestore -d destination_db --gzip /path/to/source/db

回答by Amit Kr.

If you have lost your mongoDb just try running this command:

如果您丢失了 mongoDb,请尝试运行以下命令:

mongorestore -d destination-db --gzip source-db

Where:

在哪里:

  • destination-dbis the name of the destination database
  • source-dbis the name of the source database.
  • destination-db是目标数据库的名称
  • source-db是源数据库的名称。

回答by Matthew Beck

With mongorestore, the path of those dump files is a required parameter; you've got that right so far, by indicating db.

使用 mongorestore,这些转储文件的路径是必需参数;到目前为止,通过指示 db,您已经正确了。

It is also a good idea as Peter has said to indicate a database to restore the dump files into collections with a /d switch.

这也是一个好主意,因为 Peter 曾说过使用 /d 开关指示一个数据库将转储文件恢复到集合中。

Something I didn't realize while struggling with this is that a mongod must be running to consume the restoration. If you have more than 1 mongod running, you should definitely indicate a port with the --port switch. The code that worked for me was:

在努力解决这个问题时我没有意识到的是,必须有一个 mongod 正在运行以消耗恢复。如果您有 1 个以上的 mongod 正在运行,您绝对应该使用 --port 开关指示一个端口。对我有用的代码是:

mongod --dbpath config --port 27019 --logpath log.config --logappend

And in another CLI:

在另一个 CLI 中:

mongorestore --port 27019 /d config config

followed by

其次是

mongo localhost:27019/config

to verify that the collections were filled properly.

以验证集合是否已正确填充。

回答by Ankit Kumar Rajpoot

Try this one.

试试这个。

mongorestore -db dataBaseName dataBasePath

回答by avivamg

In order to import data to your mongodb ,You need to specify --db configurationin mongorestore function with name and path, this works for me for bson and json files as well:

为了将数据导入您的 mongodb ,您需要在 mongorestore 函数中使用名称和路径指定--db 配置,这也适用于 bson 和 json 文件:

mongorestore --db <dbName> <dbPath>

check the data was imported properly using mongo cli

使用 mongo cli 检查数据是否正确导入

mongo
show databases
use <dbName>
show collections