MongoDB 从转储恢复后仍然显示空集合

MongoDB still shows empty collections after restoring from dump

在 mongodump 之后,我做了 mongorestore 似乎工作正常

heathers-air:db heathercohen$ mongorestore -v -host localhost:27017
2015-02-06T11:22:40.027-0800 creating new connection to:localhost:27017
2015-02-06T11:22:40.028-0800 [ConnectBG] BackgroundJob starting: ConnectBG
2015-02-06T11:22:40.028-0800 connected to server localhost:27017 (127.0.0.1)
2015-02-06T11:22:40.028-0800 connected connection!
connected to: localhost:27017
2015-02-06T11:22:40.030-0800 dump/langs.bson
2015-02-06T11:22:40.030-0800    going into namespace [dump.langs]
Restoring to dump.langs without dropping. Restored data will be inserted without raising errors; check your server log
file dump/langs.bson empty, skipping
2015-02-06T11:22:40.030-0800    Creating index: { key: { _id: 1 }, name: "_id_", ns: "dump.langs" }
2015-02-06T11:22:40.031-0800 dump/tweets.bson
2015-02-06T11:22:40.031-0800    going into namespace [dump.tweets]
Restoring to dump.tweets without dropping. Restored data will be inserted without raising errors; check your server log
     file size: 4877899
30597 objects found
2015-02-06T11:22:41.883-0800    Creating index: { key: { _id: 1 }, name: "_id_", ns: "dump.tweets" }

当我尝试访问数据时,它仍然是空的,恢复前的样子:

> show dbs
admin    (empty)
dump     0.078GB
local    0.078GB
tweets   (empty)
twitter  (empty)

说找到了30597个物体,它们去哪儿了?

他们进入转储数据库,然后进入集合 dump.tweetsdump.langs。这些文件包含在文件夹 dump 中的事实意味着 mongorestore 认为它们应该恢复到数据库 dump(从路径推断)。详细的输出甚至明确指出数据被放入 dump.langsdump.tweets 中。

如果您指定要还原到的数据库(使用 -d)并还原特定文件,您将能够将文档还原到您想要的数据库。或者,您可以通过 运行:

简单地查看转储数据库
use dump;
db.tweets.find();
db.langs.find();