Mongorestore没有恢复数据

时间:2015-03-04 18:38:50

标签: mongodb mongorestore

我正在尝试恢复单个集合的现有mongodump。运行mongo还原后,不会显示任何错误,并且数据不在集合中。有没有任何已知的原因如何发生这种情况?我希望如果由于某种原因没有插入数据,则会在日志中提供错误。

要创建并尝试恢复转储,我按照此问题提供的答案: How to use mongodump for 1 collection

我在另一台服务器上创建了一个新数据库,它有一个空集合。我检查了mongo日志文件,没有错误,它显示连接打开并进行身份验证,然后在下一行断开连接。

mongorestore -vvvvv -u user -p 'password' --db=MyDatabase --collection=MyCollection dump1/MyCollection.bson 
2015-03-04T18:20:31.331+0000 creating new connection to:127.0.0.1:27017
2015-03-04T18:20:31.332+0000 [ConnectBG] BackgroundJob starting: ConnectBG
2015-03-04T18:20:31.332+0000 connected to server 127.0.0.1:27017 (127.0.0.1)
2015-03-04T18:20:31.332+0000 connected connection!
connected to: 127.0.0.1
2015-03-04T18:20:31.333+0000 drillDown: dump1/MyCollection.bson
2015-03-04T18:20:31.333+0000 dump1/MyCollection.bson
2015-03-04T18:20:31.333+0000    going into namespace [MyDatabase.MyCollection]
Restoring to MyDatabase.MyCollection without dropping. Restored data will be inserted without raising errors; check your server log
         file size: 94876
130 objects found
2015-03-04T18:20:31.336+0000    Creating index: { key: { _id: 1 }, name: "_id_", ns: "MyDatabase.MyCollection" }
2015-03-04T18:20:31.340+0000    Creating index: { key: { geometry: "2dsphere" }, name: "geometry_2dsphere", ns: "MyDatabase.MyCollection", 2dsphereIndexVersion: 2 }

日志文件:

2015-03-04T18:20:31.333+0000 [conn874]  authenticate db: MyDatabase { authenticate: 1, nonce: "xxx", user: "user", key: "xxx" }
2015-03-04T18:20:31.342+0000 [conn874] end connection 127.0.0.1:59420 (25 connections now open)

我在原点和目的地使用的查询是:

db.MyCollection.find()

在原始服务器上,该集合有130个元素,这些元素也显示在mongorestore outup"找到130个对象"。

编辑:

我在mongorestore命令中添加了--drop选项。日志文件输出清楚地显示它正在空集合上创建索引。

2015-03-20T15:03:57.565+0000 [conn61965]  authenticate db: MyDatabase { authenticate: 1, nonce: "xxx", user: "user", key: "xxx" }
2015-03-20T15:03:57.566+0000 [conn61965] CMD: drop MyDatabase.MyCollection
2015-03-20T15:03:57.631+0000 [conn61965] build index on: MyDatabase.MyCollection properties: { v: 1, key: { _id: 1 }, name: "_id_", ns: "MyDatabase.MyCollection" }
2015-03-20T15:03:57.631+0000 [conn61965]         added index to empty collection
2015-03-20T15:03:57.652+0000 [conn61965] build index on: MyDatabase.MyCollection properties: { v: 1, key: { geometry: "2dsphere" }, name: "geometry_2dsphere", ns: "MyDatabase.MyCollection", 2dsphereIndexVersion: 2 }
2015-03-20T15:03:57.652+0000 [conn61965]         added index to empty collection
2015-03-20T15:03:57.654+0000 [conn61965] end connection 127.0.0.1:59456 (21 connections now open)

1 个答案:

答案 0 :(得分:3)

所以问题最终是我尝试进行恢复的用户只有read和dbAdmin角色。我创建了一个单独的用户,以便应用程序使用的常规用户没有管理权限。将用户的角色从read更改为readWrite后,它按预期工作。

老实说,如果用户没有正确的权限,我真的希望日志在没有正确权限的情况下尝试运行恢复时显示某种错误。

相关问题